因此,我想一直询问用户要使用哪种货币,直到他们输入“ USD”或“ GEL”为止,但这似乎行不通。帮助将不胜感激
import datetime
db = [
{
'product': 'cola',
'price': {
'USD': '2',
'GEL': '6'
},
'amount': 20,
'validity': '17/12/2019'
},
{
'product': 'cake',
'price': {
'USD': '3',
'GEL': '9'
},
'amount': 15,
'validity': '17/12/2019'
},
{
'product': 'tea',
'price': {
'USD': '1',
'GEL': '3'
},
'amount': 14,
'validity': '17/12/2019'
},
]
amount_of_product = {}
validity_of_product = {}
prices_of_product = {}
for i in db:
amount_of_product.update({i["product"]: i["amount"]})
validity_of_product.update({i["product"]: i["validity"]})
prices_of_product.update({i["product"]: i["price"]})
adLoop = True
totalGEL = 0
totalUSD = 0
while adLoop:
user_input = input("Please enter a product name: ").lower()
if user_input in amount_of_product.keys() and validity_of_product.keys():
print(f"Currently, we have {amount_of_product[user_input]} amount of {user_input} left, "
f"which are valid through {validity_of_product[user_input]}")
user_input_two = input("Please enter the amount: ")
while not user_input_two.isdigit():
user_input_two = input("Please enter a number: ")
user_input_three = input("In which currency would you like to pay in?(GEL or USD): ").upper()
while user_input_three != "GEL" or not user_input_three != "USD":
user_input_three = input("In which currency would you like to pay in:?(GEL or USD only) ").upper()
price = prices_of_product[user_input][user_input_three]
total = int(user_input_two) * int(price)
if user_input_three == "GEL":
totalGEL += total
print(f"Your order is: {user_input_two} {user_input} and total price for it is: {total}₾")
elif user_input_three == "USD":
totalUSD += total
print(f"Your order is: {user_input_two} {user_input} and total price for it is: {total}$")
stop_or_order = input("Would you like to add anything else?: ")
if stop_or_order == "yes":
adLoop = True
elif stop_or_order == "no":
adLoop = False
print(test)
这就是我被困住的地方。在这种情况下,一个语句为true,并且如果用户输入“ USD”,而仅输入“ GEL”,它就不会中断。如果用户输入其中之一,我希望它停止。
user_input_three = input("In which currency would you like to pay in?(GEL or USD): ").upper()
while user_input_three != "GEL" or not user_input_three != "USD":
user_input_three = input("In which currency would you like to pay in:?(GEL or USD only)