I have a function that returns a string of student names and maximum grades: Jade: 82. I also have a test function that has a test case that expects the returned value of the function to be a multiline string.
import sys
grades = '''Jade,50,64,82,14
Brenda,90,67,73,80
Chris,75,75,75,75
John,100,85,90,99'''
def maximum(l: list):
maxVal = 0
for i in l:
maxVal = max(maxVal, int(i))
return maxVal
def max_scores(grades):
grades = grades.splitlines()
finalGrades = []
for i in grades:
finalGrades.append(i.split(","))
ans = ""
for i in finalGrades:
maxVal = maximum(i[1:])
ans = ans + i[0] + ": " + str(maxVal)+"\n"
return ans
max_scores(grades)
Output (without including print)
'Jade: 82\nBrenda: 90\nChris: 75\nJohn: 100\n'
Output (with print in the return statement)
print(max_scores(grades))
Jade: 82
Brenda: 90
Chris: 75
John: 100
The test case
def test_max_scores():
print("Testing get_max_scores()...", end="")
grades = '''Jade,50,64,82,14
Brenda,90,67,73,80
Chris,75,75,75,75
John,100,85,90,99'''
assert((max_scores(grades)) == '''Jade: 82
Brenda: 90
Chris: 75
John: 100''')
print("... done!")
I am unable to get the function to return the multiline string the test case is expecting.