- #1
acurate
- 17
- 1
Homework Statement
I made a two-dimensional array program, but now I need some help to alter the program in the print zone.
The Attempt at a Solution
Code:
import sys
students = []
grades = []
while True:
student = input ("Enter a name: ").replace(" ","")
if student.isalpha() == True and student != "0":
while True:
grade = input("Enter a grade: ").replace(" ","")
if grade == "0" or grade == 0:
print ("\n")
print ("A zero is entered.")
sys.exit(0)
if grade.isdigit()== True:
grade = int(grade)
if grade >= 1 and grade <= 10:
if student in students:
index = students.index(student)
grades[index].append(grade)
break
else:
students.append(student)
grades.append([grade])
break
else:
print("Invalid grade.")
elif student == "0":
print("A zero is entered.")
break
else:
print ("Invalid name.")
for i in range(0,len(students)):
print("NAME: ", students[i])
print("GRADE: ", grades[i])
print("AVERAGE: ", round(sum(grades[i])/len(grades[i]),1), "\n")
It prints out like this:
Code:
NAME: Jack
GRADE: [8, 7, 9]
AVERAGE: 8.0
How do I turn the
Code:
GRADE: [8, 7, 9]
Code:
GRADE: 8, 7, 9