Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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:

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.3k views
Welcome To Ask or Share your Answers For Others

1 Answer

  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):

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...