while 1: Li = ['手机','电脑','Ipad','无线耳机','运动鞋'] for Loop in Li: print('{}\t{}'.format(Li.index(Loop)+1,Loop)) Num_chioce = input("请输入你选择的商品号,输入Q退出:") if Num_chioce.isdigit(): Num_chioce = int(Num_chioce) if Num_chioce > 0 and Num_chioce <= len(Li): print('你选择的商品是:' '{}'.format(Li[Num_chioce - 1])) else: print('请输入有效数字') elif Num_chioce.upper() == 'Q': break else: print('请输入正确的数字')
标签:Day6,Li,Python,chioce,Num,Loop,购物车 From: https://www.cnblogs.com/leishu/p/16864262.html