Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.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 3.x 如何在python中增加输入语句?_Python 3.x - Fatal编程技术网

Python 3.x 如何在python中增加输入语句?

Python 3.x 如何在python中增加输入语句?,python-3.x,Python 3.x,我的问题是,当它通过所有12个名字的循环时,如何让它显示为“学生1的名字”、“学生2的名字”等等 students = 12 for x in range(students): name = str(input('Student name: ')) grade = int(input('Enter average grade: ')) 要添加到Andrew Li的注释中,还可以使用“+”运算符在python中直接附加字符串: 如果不想使用format方法,也可以尝试以下方法:

我的问题是,当它通过所有12个名字的循环时,如何让它显示为“学生1的名字”、“学生2的名字”等等

students = 12
for x in range(students):
    name = str(input('Student name: '))
    grade = int(input('Enter average grade: '))

要添加到Andrew Li的注释中,还可以使用“+”运算符在python中直接附加字符串:

如果不想使用format方法,也可以尝试以下方法:

name = input("Student " + str(x + 1) + " name: ")
input('Student{}name'。格式(x+1))