[英]How to make a loop x in python, attribute a value to a variable and print this value each time?
I want to ask the user how many times the loop has to be made and inside the loop, put a value in a variable and then print all the values in the loop. 我想问用户循环必须执行多少次并在循环内,将一个值放入变量,然后在循环中打印所有值。
x = int(input("Number of loops: "))
for y in range(x):
z = str(input())
print (z)
If the user types "2" i want the loop to happen 2 times and each time ask for a name to (z) and then print all the names I gave to z, what am i doing wrong? 如果用户键入“ 2”,我希望循环发生2次,并且每次都要求给(z)一个名称,然后打印我给z提供的所有名称,那我在做什么错呢?
I'm not sure about what you want, do you want to print all the input to z
? 我不确定您想要什么,是否要将所有输入都打印到
z
?
x = int(input("Number of loops: "))
z = []
for y in range(x):
z.append(str(input()))
print(z)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.