Python如何接收可变数量的输入?
有没有办法让Python根据用户的输入来接收多个数字呢?比如说:
x = input("how many numbers do you have?")
如果x等于5,程序就会依次询问用户输入第一个数字、第二个数字、第三个数字,等等……
这样做可以吗?
1 个回答
2
amount = int(input("Enter the amount of numbers that you have: "))
numbers = []
for i in range(amount):
new = input('Enter number {}: '.format(i+1))
numbers.append(new)
print(numbers)
你可能需要了解一下Python中的循环。