Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python给我的是索引号,而不是列表中的输入。_Python_List - Fatal编程技术网

Python给我的是索引号,而不是列表中的输入。

Python给我的是索引号,而不是列表中的输入。,python,list,Python,List,Python给我的是索引号,而不是列表中的输入。我试图让用户提供输入,然后让它将其存储到打印的列表中。我该怎么修 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

Python给我的是索引号,而不是列表中的输入。我试图让用户提供输入,然后让它将其存储到打印的列表中。我该怎么修

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)

它在需要打印之前工作正常。

这是因为您没有将第二个输入指定给变量!,然后,您只需插入
for
循环中使用的索引

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)

这是因为您没有将第二个输入指定给变量!,然后,您只需插入
for
循环中使用的索引

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)

您认为第二个
输入返回的值会发生什么变化?您认为第二个
输入返回的值会发生什么变化?非常感谢!我一辈子都想不出来。太好了!!,这在我身上经常发生。很高兴帮助你。非常感谢!我一辈子都想不出来。太好了!!,这在我身上经常发生。很高兴帮助你。