Problem Statement

Write a program that will calculate weighted grades for students in a college course. The input will be given in a comma-delimited format. The first line will contain a number of weights as floating-point numbers, separated by commas. The first entry should be ignored.

Each subsequent line of input will contain information for a student. The first entry on that line will contain that student’s name. The rest of the line will contain that student’s scores on each assignment as an integer value, separated by commas. Input will be terminated by the end of the input file, or by a blank line when input is provided via the terminal.

It is guaranteed that at least two lines of input will be provided, the first containing the weights and at least one additional line containing data for a student. In addition, it is guaranteed that each line of input will contain the same number of parts.

The program should output the student’s name, followed by a colon, and a space, and then the student’s score. The score should be formatted to be exactly 5 characters wide, with exactly two characters after the decimal point.

Yikes!

Let's break it down into smaller parts

# Load required modules
import sys

If an argument is present, we are reading from a file

specified in sys.argv[1]

if len(sys.argv) > 1: reader = open(sys.argv[1])

If no argument, read from stdin

else: reader = sys.stdin

-=-=-=-=- MORE CODE GOES HERE -=-=-=-=-

Skeleton


The first line will contain a number of weights as floating-point numbers, separated by commas. The first entry should be ignored.


The first line will contain a number of weights as floating-point numbers, separated by commas. The first entry should be ignored.

weightLine = reader.readline()

The first line will contain a number of weights as floating-point numbers, separated by commas. The first entry should be ignored.

weightLine = reader.readline()

The first line will contain a number of weights as floating-point numbers, separated by commas. The first entry should be ignored.

weightLine = reader.readline()
weightParts = weightLine.split(",")

The first line will contain a number of weights as floating-point numbers, separated by commas. The first entry should be ignored.

weightLine = reader.readline()
weightParts = weightLine.split(",")

The first line will contain a number of weights as floating-point numbers, separated by commas. The first entry should be ignored.

weightLine = reader.readline()
weightParts = weightLine.split(",")

weights = []

The first line will contain a number of weights as floating-point numbers, separated by commas. The first entry should be ignored.

weightLine = reader.readline()
weightParts = weightLine.split(",")

weights = []

The first line will contain a number of weights as floating-point numbers, separated by commas. The first entry should be ignored.

weightLine = reader.readline()
weightParts = weightLine.split(",")

weights = []

for i in range(0, len(weightParts)): weights.append(weightParts[i])

The first line will contain a number of weights as floating-point numbers, separated by commas. The first entry should be ignored.

weightLine = reader.readline()
weightParts = weightLine.split(",")

weights = []

for i in range(0, len(weightParts)): weights.append(weightParts[i])

The first line will contain a number of weights as floating-point numbers, separated by commas. The first entry should be ignored.

weightLine = reader.readline()
weightParts = weightLine.split(",")

weights = []

for i in range(0, len(weightParts)): weights.append(float(weightParts[i]))

The first line will contain a number of weights as floating-point numbers, separated by commas. The first entry should be ignored.

weightLine = reader.readline()
weightParts = weightLine.split(",")

weights = []

for i in range(0, len(weightParts)): weights.append(float(weightParts[i]))

The first line will contain a number of weights as floating-point numbers, separated by commas. The first entry should be ignored.

weightLine = reader.readline()
weightParts = weightLine.split(",")

weights = []

for i in range(0, len(weightParts)): weights.append(float(weightParts[i]))

The first line will contain a number of weights as floating-point numbers, separated by commas. The first entry should be ignored.

weightLine = reader.readline()
weightParts = weightLine.split(",")

weights = [] weights.append(0.0)

for i in range(1, len(weightParts)): weights.append(float(weightParts[i]))

The first line will contain a number of weights as floating-point numbers, separated by commas. The first entry should be ignored.

weightLine = reader.readline()
weightParts = weightLine.split(",")

weights = [] weights.append(0.0)

for i in range(1, len(weightParts)): weights.append(float(weightParts[i]))

The first line will contain a number of weights as floating-point numbers, separated by commas. The first entry should be ignored.


Each subsequent line of input will contain information for a student. ... Input will be terminated by the end of the input file, or by a blank line when input is provided via the terminal.


Each subsequent line of input will contain information for a student. ... Input will be terminated by the end of the input file, or by a blank line when input is provided via the terminal.

for line in reader:

Each subsequent line of input will contain information for a student. ... Input will be terminated by the end of the input file, or by a blank line when input is provided via the terminal.

for line in reader:

Each subsequent line of input will contain information for a student. ... Input will be terminated by the end of the input file, or by a blank line when input is provided via the terminal.

for line in reader:

# parse the input

Each subsequent line of input will contain information for a student. ... Input will be terminated by the end of the input file, or by a blank line when input is provided via the terminal.

for line in reader:

parse the input

Each subsequent line of input will contain information for a student. ... Input will be terminated by the end of the input file, or by a blank line when input is provided via the terminal.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parse the input

Each subsequent line of input will contain information for a student. ... Input will be terminated by the end of the input file, or by a blank line when input is provided via the terminal.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parse the input

Each subsequent line of input will contain information for a student. ... Input will be terminated by the end of the input file, or by a blank line when input is provided via the terminal.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parse the input

The first entry on that line will contain that student’s name. The rest of the line will contain that student’s scores on each assignment as an integer value, separated by commas.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parse the input

The first entry on that line will contain that student’s name. The rest of the line will contain that student’s scores on each assignment as an integer value, separated by commas.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parts = line.split(",")

The first entry on that line will contain that student’s name. The rest of the line will contain that student’s scores on each assignment as an integer value, separated by commas.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parts = line.split(",")

The first entry on that line will contain that student’s name. The rest of the line will contain that student’s scores on each assignment as an integer value, separated by commas.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parts = line.split(",")

for j in range(1, len(parts)): parts[j]

The first entry on that line will contain that student’s name. The rest of the line will contain that student’s scores on each assignment as an integer value, separated by commas.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parts = line.split(",")

for j in range(1, len(parts)): parts[j]

The first entry on that line will contain that student’s name. The rest of the line will contain that student’s scores on each assignment as an integer value, separated by commas.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parts = line.split(",")

for j in range(1, len(parts)): int(parts[j])

The first entry on that line will contain that student’s name. The rest of the line will contain that student’s scores on each assignment as an integer value, separated by commas.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parts = line.split(",")

for j in range(1, len(parts)): int(parts[j])

Write a program that will calculate weighted grades for students in a college course.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parts = line.split(",")

for j in range(1, len(parts)): int(parts[j])

Write a program that will calculate weighted grades for students in a college course.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parts = line.split(",")

for j in range(1, len(parts)): int(parts[j])

Write a program that will calculate weighted grades for students in a college course.

Total =
Sum(Score[i] * Weight[i])

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parts = line.split(",")

for j in range(1, len(parts)): weights[j] * int(parts[j])

Write a program that will calculate weighted grades for students in a college course.

Total =
Sum(Score[i] * Weight[i])

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parts = line.split(",")

totalScore = 0.0 for j in range(1, len(parts)): totalScore += weights[j] * int(parts[j])

Write a program that will calculate weighted grades for students in a college course.

Total =
Sum(Score[i] * Weight[i])

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parts = line.split(",")

totalScore = 0.0 for j in range(1, len(parts)): totalScore += weights[j] * int(parts[j])

The program should output the student’s name, followed by a colon, and a space, and then the student’s score. The score should be formatted to be exactly 5 characters wide, with exactly two characters after the decimal point.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parts = line.split(",")

totalScore = 0.0 for j in range(1, len(parts)): totalScore += weights[j] * int(parts[j])

The program should output the student’s name, followed by a colon, and a space, and then the student’s score. The score should be formatted to be exactly 5 characters wide, with exactly two characters after the decimal point.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parts = line.split(",")

totalScore = 0.0 for j in range(1, len(parts)): totalScore += weights[j] * int(parts[j])

print()

The program should output the student’s name, followed by a colon, and a space, and then the student’s score. The score should be formatted to be exactly 5 characters wide, with exactly two characters after the decimal point.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parts = line.split(",")

totalScore = 0.0 for j in range(1, len(parts)): totalScore += weights[j] * int(parts[j])

print()

The program should output the student’s name, followed by a colon, and a space, and then the student’s score. The score should be formatted to be exactly 5 characters wide, with exactly two characters after the decimal point.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parts = line.split(",")

totalScore = 0.0 for j in range(1, len(parts)): totalScore += weights[j] * int(parts[j])

print("".format())

The program should output the student’s name, followed by a colon, and a space, and then the student’s score. The score should be formatted to be exactly 5 characters wide, with exactly two characters after the decimal point.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parts = line.split(",")

totalScore = 0.0 for j in range(1, len(parts)): totalScore += weights[j] * int(parts[j])

print("".format())

The program should output the student’s name, followed by a colon, and a space, and then the student’s score. The score should be formatted to be exactly 5 characters wide, with exactly two characters after the decimal point.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parts = line.split(",")

totalScore = 0.0 for j in range(1, len(parts)): totalScore += weights[j] * int(parts[j])

print("{}: ".format(parts[0]))

The program should output the student’s name, followed by a colon, and a space, and then the student’s score. The score should be formatted to be exactly 5 characters wide, with exactly two characters after the decimal point.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parts = line.split(",")

totalScore = 0.0 for j in range(1, len(parts)): totalScore += weights[j] * int(parts[j])

print("{}: “.format(parts[0]))

The program should output the student’s name, followed by a colon, and a space, and then the student’s score. The score should be formatted to be exactly 5 characters wide, with exactly two characters after the decimal point.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parts = line.split(”,")

totalScore = 0.0 for j in range(1, len(parts)): totalScore += weights[j] * int(parts[j])

print("{}: {}".format(parts[0], totalScore))

The program should output the student’s name, followed by a colon, and a space, and then the student’s score. The score should be formatted to be exactly 5 characters wide, with exactly two characters after the decimal point.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parts = line.split(",")

totalScore = 0.0 for j in range(1, len(parts)): totalScore += weights[j] * int(parts[j])

print("{}: {}".format(parts[0], totalScore))

The program should output the student’s name, followed by a colon, and a space, and then the student’s score. The score should be formatted to be exactly 5 characters wide, with exactly two characters after the decimal point.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parts = line.split(",")

totalScore = 0.0 for j in range(1, len(parts)): totalScore += weights[j] * int(parts[j])

print("{}: {:5.2f}".format(parts[0], totalScore))

The program should output the student’s name, followed by a colon, and a space, and then the student’s score. The score should be formatted to be exactly 5 characters wide, with exactly two characters after the decimal point.

for line in reader:
  if not line or len(line.strip()) == 0:
    break

parts = line.split(",")

totalScore = 0.0 for j in range(1, len(parts)): totalScore += weights[j] * int(parts[j])

print("{}: {:5.2f}".format(parts[0], totalScore))

The program should output the student’s name, followed by a colon, and a space, and then the student’s score. The score should be formatted to be exactly 5 characters wide, with exactly two characters after the decimal point.

weightLine = reader.readline()
weightParts = weightLine.split(",")

weights = [] weights.append(0.0)

for i in range(1, len(weightParts)): weights.append(float(weightParts[i]))

for line in reader: if not line or len(line.strip()) == 0: break

parts = line.split(",")

totalScore = 0.0 for j in range(1, len(parts)): totalScore += weights[j] * int(parts[j])

print("{}: {:5.2f}".format(parts[0], totalScore))

"/js/highlight.pack.js"