如何在菜单上循环其他问题?
到目前为止,我有:
loop()
selection=raw_input('How Many Apples (limit 3): ')
print ' '
if selection=='1':
p = a
print '<1 Apple added to Cart>'
break
elif selection=='2':
p = a*2
print '<2 Apples added too Cart>'
break
elif selection=='3':
p = a*3
print '<3 Apples added too Cart>'
break
else:
print '[try again]'
我想将else选项循环回到顶部,所以如果人们选择不在列表中的选项,它会再次询问!
答案 0 :(得分:0)
你几乎就在那里
while True:
selection=raw_input('How Many Apples (limit 3): ')
print ' '
if selection=='1':
p = a
print '<1 Apple added to Cart>'
break
elif selection=='2':
p = a*2
print '<2 Apples added too Cart>'
break
elif selection=='3':
p = a*3
print '<3 Apples added too Cart>'
break
else:
print '[try again]'