import sys
print('Do you want a cup of tea?')
user_input_tea = input().lower()
if user_input_tea == 'yes':
print("You feel the thirst for a nice cup of tea, now it's time to make it.")
else:
print('You feel a cup of tea is not for you.')
sys.exit(0)
equipment = []
def equipment_find(item):
if item == str(item):
print("You have acquired the " + str(item) + " , now it's time to proceed.")
equipment.append(item)
print(equipment)
else:
print("You did not enter: " + str(item))
while True:
print("Please input: " str(item))
if item == str(item):
equipment.append(item)
print(equipment)
break
print("You are going to need a kettle for this tea making process, please input kettle to acquire the kettle")
kettle = input().lower()
equipment_find(kettle)
上面的代码就是我所拥有的。我想要它所以我已经有用户输入的变量,无论如何我可以自动化函数触发for循环或其他东西。
答案 0 :(得分:0)
以下是我认为您希望实现的简化示例。我们指定所需成分的列表,并要求用户输入项目,直到他们拥有所有成分。我在比较期间使用set()因为我们不关心输入项目的顺序。
requiredItemsList = ['kettle', 'water', 'spoon', 'sugar']
enteredItmesList = []
print("You feel the thirst for a nice cup of tea, now it's time to make it.")
while set(requiredItemsList) != set(enteredItmesList):
item = input('Enter an item: ')
if item in requiredItemsList and item not in enteredItmesList:
print('You have acquired the', item, ", now it's time to proceed.")
enteredItmesList.append(item)
else:
print('The item you entered is not valid. Please try again.')
print('You have aquired all needed items!')
print(enteredItmesList)