Skip to content
ExamSpine

Lesson 5.10 · Write it

Scores on one line

A whole programPython or Java6 tests, 4 of them hidden

On a phone? Put the lines in order instead

Write a program that reads one line holding a name and some test scores, and prints a short report.

  1. The line has the name first, then one or more scores. The parts are separated by commas, with no spaces around the commas. For example: Ana,72,85,90.
  2. The name has no commas in it, but it can have spaces. Every score is a whole number from 0 to 100.
  3. Print three lines: Name: and the name, then Scores: and how many scores there are, then Total: and the scores added up.

For the example line, the program prints:

Name: Ana
Scores: 3
Total: 247

Your program is run several times. Only what it prints is checked.

Running Java here comes later. You can put this answer's lines in order instead. You can still write your Java answer (it stays while this page is open) and compare it with our worked solution. Or try this exercise in Python.

Examples

Your program is run 6 times: the 2 examples below, and 4 hidden ones that check the rules above. Only what it prints is checked.

  • the example: a name and three scores (rule 3)

    You type

    1. typed: Ana,72,85,90

    It prints

    Name: Ana
    Scores: 3
    Total: 247
  • a name and only one score (rule 1)

    You type

    1. typed: Leo,50

    It prints

    Name: Leo
    Scores: 1
    Total: 50
solution.pySolution.java