-1

Need to obtain marks for three subjects for several students and store them in a dictionary. Student name and marks will be the key and value respectively. Display the students name and their marks as follows,

student1 : mark1, mark2, mark3
student2 : mark1, mark2, mark3

I have tried this...

data = {}

while True:
    stuName = input("Student Name: ")
    math_marks = int(input("Math marks: "))
    physics_marks = int(input("Physics Marks: "))
    chemistry_marks = int(input("Chemistry Marks: "))

    data[stuName] = [math_marks, physics_marks, chemistry_marks]

    quit = input("Quit? ")
    if quit == 'q':
        break

print(*[str(k) + ' : ' + str(v) for k, v in data.items()], sep='\n')

But it gives the OUTPUT like...

student1 : [mark1, mark2, mark3]
student2 : [mark1, mark2, mark3]

EXPECTED OUTPUT

student1 : mark1, mark2, mark3
student2 : mark1, mark2, mark3
Barmar
  • 741,623
  • 53
  • 500
  • 612

1 Answers1

0

Replace str(v) with ", ".join(v) to convert the list to a comma-delimited string.

Barmar
  • 741,623
  • 53
  • 500
  • 612