-1

How would I make this repeat to the amount of students entered? Everything I've tried doesn't work.

numStudents = input("Enter the number of students: ")

while true:
    for x in range(len(numStudents)):
        name = input("Student Name: ")
        number = input("Student Number: ")

ex.

Enter the number of students: 3

Student name:
Student Number:

Student name:
Student Number:

Student name:
Student Number:
Idos
  • 15,053
  • 14
  • 60
  • 75

1 Answers1

1
  1. Get rid of the while true: (it's called True in Python, and there's no reason for an infinite loop even if you fixed that)
  2. Replace for x in range(len(numStudents)): with for x in range(int(numStudents)): to loop numStudents times, rather than looping "length of the string stored in numStudents" times. Or just change numStudents = input("Enter the number of students: ") to numStudents = int(input("Enter the number of students: ")) to make it an int from the get go, and make the for loop for x in range(numStudents):
ShadowRanger
  • 143,180
  • 12
  • 188
  • 271