user10605606
user10605606

Reputation:

Python gives me the index numbers instead of the input in the list.

Python gives me the index numbers instead of the input in the list. I'm trying to get the user to give input and then have it store that into a printed list. How do I fix it?

number_of_grades = int(input('How many quizzes have you had?'))

grade_list = []

for grades in range(number_of_grades):
    input('Please input a grade from the quiz.')
    grade_list.insert(0, grades)

print(grade_list)

It works just fine up until it needs to be printed.

Upvotes: 0

Views: 42

Answers (1)

Cheche
Cheche

Reputation: 1516

It's because you are not assigning your second input to a variable!, then you are just inserting the index used in the for loop.

number_of_grades = int(input('How many quizzes have you had?'))
grade_list = [] 
for grades in range(number_of_grades): 
    value = input('Please input a grade from the quiz.') 
    grade_list.insert(0, value)
print(grade_list)

Upvotes: 3

Related Questions