这是我的代码:
while type(checkout) == str:
if checkout == '1':
while total_price_final<50:
print('Spend another $',50.00-total_price_final, 'to enjoy free delivery.Else a cost of $10 will be added to your cart if you choose delivery')
print('Would you like to continue shopping?\n[1]Yes\n[2]No')
delivery1=input('Please choose an option:')
while delivery1>'1':
print('What would you like to do?\n[1]Proceed with delivery\n[2]Proceed without delivery')
delivery2 = input('Please choose an option:')
if delivery2<'1' or delivery2>'2':
print('Please choose a valid option!')
if delivery2=='1' or delivery1=='2':
print('Alright')
break
if delivery1=='1':
break
break
elif checkout=='2'or delivery1=='1':
break
我被困在交付1的while循环中(如果我选择选项2,它将使我返回),请帮助。希望能提供任何帮助。谢谢!
我认为您在输入2后无限循环
print('What would you like to do?\n[1]Proceed with delivery\n[2]Proceed without delivery')
delivery2 = input('Please choose an option:')
这是真的吗?如果是这样,我相信是因为您从未指定delivery2 == 2。
同样,正如chepner所建议的,input()函数返回str。无需检查checkout
的类型