比较 python 列表中的数字输入
Comparing numerical input in python list
正在尝试创建列表。
n = 0
while n = 0:
number = int(input ("What number of groceries do you wish to purchase?"))
有什么方法可以让我编写一段代码,根据用户输入的数字询问用户他们想要什么杂货。
类似
while number = int(1,20):
print ("What grocery would you like to purchase?")
只有那个不会打印那么多次...
不太清楚你想要什么,但你可以简单地做
number = int(input ("What number of groceries do you wish to purchase?"))
groceries = []
#Ask for grocery input number of times
for i in range(number):
grocery = input("What grocery would you like to purchase?")
groceries.append(grocery)
print(groceries)
样本输出将是
What number of groceries do you wish to purchase?3
What grocery would you like to purchase?Apple
What grocery would you like to purchase?Banana
What grocery would you like to purchase?Orange
['Apple', 'Banana', 'Orange']
正在尝试创建列表。
n = 0
while n = 0:
number = int(input ("What number of groceries do you wish to purchase?"))
有什么方法可以让我编写一段代码,根据用户输入的数字询问用户他们想要什么杂货。
类似
while number = int(1,20):
print ("What grocery would you like to purchase?")
只有那个不会打印那么多次...
不太清楚你想要什么,但你可以简单地做
number = int(input ("What number of groceries do you wish to purchase?"))
groceries = []
#Ask for grocery input number of times
for i in range(number):
grocery = input("What grocery would you like to purchase?")
groceries.append(grocery)
print(groceries)
样本输出将是
What number of groceries do you wish to purchase?3
What grocery would you like to purchase?Apple
What grocery would you like to purchase?Banana
What grocery would you like to purchase?Orange
['Apple', 'Banana', 'Orange']