所以我正在嘗試撰寫一個結帳函式,這就是它的外觀,目前在選擇付款方式時它不起作用我認為它是回圈或者我在函式中使用了 checkout == 兩次。
def checkout(self):
while True:
if not shopping_cart:
print("Your cart is empty, please add item to proceed to checkout")
else:
checkout = int(input('''Do you want to proceed to checkout?
1. Yes
2. No '''))
if checkout == 1:
checkout = input('''Please select how you would like to pay for your purchase:
1. Gift Voucher
2. Credit / Debit Card
3. Paypal''')
if checkout == 2:
break
else:
if checkout == 1:
input("Please enter your gift voucher code")
print("Thank you")
elif checkout == 2:
input("Please enter your Credit / Debit card information")
print("Thank you")
elif checkout == 3:
input("vffsdfsdfsd")
print("TA")
else:
print("Please select a valid payment method")
break
uj5u.com熱心網友回復:
這是因為您使用相同的變數Do you want to proceed to checkout?和Please select how you would like to pay變數嘗試更改payment method型別的變數payment_method
def checkout(self):
while True:
if not shopping_cart:
print("Your cart is empty, please add item to proceed to checkout")
else:
checkout = int(input('''Do you want to proceed to checkout?
1. Yes
2. No '''))
if checkout == 1:
payment_method = input('''Please select how you would like to pay for your purchase:
1. Gift Voucher
2. Credit / Debit Card
3. Paypal''')
if checkout == 2:
break
else:
if payment_method == 1:
input("Please enter your gift voucher code")
print("Thank you")
elif payment_method == 2:
input("Please enter your Credit / Debit card information")
print("Thank you")
elif payment_method == 3:
input("vffsdfsdfsd")
print("TA")
else:
print("Please select a valid payment method")
break
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/325042.html
