# Homework Help: How to change a two-dimensional array print into normal?

Tags:
1. Mar 27, 2015

### acurate

1. The problem statement, all variables and given/known data
I made a two-dimensional array program, but now I need some help to alter the program in the print zone.

3. The attempt at a solution
Code (Text):

import sys
students = []

while True:
student = input ("Enter a name: ").replace(" ","")
if  student.isalpha() == True and student != "0":
while True:
print ("\n")
print ("A zero is entered.")
sys.exit(0)
if student in students:
index = students.index(student)
break
else:
students.append(student)
break
else:
elif student == "0":
print("A zero is entered.")
break
else:
print ("Invalid name.")
for i in range(0,len(students)):
print("NAME: ", students[i])
It prints out like this:

Code (Text):

NAME:  Jack
AVERAGE:  8.0

How do I turn the
Code (Text):
so that the numbers would go
Code (Text):
?

2. Mar 27, 2015

### Staff: Mentor

The short answer is, you can't print the grades without the brackets. The reason for this is how your program is working. For a given student, your grades list contains only one element -- a list of the grades that you enter using this line:
Code (Text):
etc.
The fix for this is that after you input each grade (not all of them at once), you append that grade to your list.

Here's some code that I wrote that fixes the problem. It works correctly for a single student, but it doesn't work correctly if you enter more than one student, since grades is only one list -- IOW, there are not separate grades lists for each student. You might consider making grades a list of lists, where the list at index 1 contains the grades for student 1, and the list at index 2 contains the grades for student 2, and so on.
Code (Python):

import sys
students = []

while True:
student = input ("Enter a name: ").replace(" ","")
if  student.isalpha() == True and student != "0":
students.append(student)
while True:
print ("\n")
print ("A zero is entered.")
break
else:

else:
break

students_len = len(students)
for i in range(students_len):
print("NAME: ", students[i])