GItHub base 03-

"""  03  输出商品列表,用户输入序号,显示用户选中的商品
    li = ["手机", "电脑", '鼠标垫', '游艇'] """
li = ["手机", "电脑", '鼠标垫', '游艇']
cart = []
while True:

    for i in range(len(li)):
        print('商品{}的序号为:{},'.format(i, li[i]))
    while True:
        s = input("输入你想要的商品序号,'q',退出")
        if s.isdigit():
            s = int(s)
            if s >= 0 and s < len(li):
                print('您选择的商品为{}'.format(li[s]))
                cart.append(li[s])
                print(cart)
                n = input("是否继续选购:'任意键继续选购,'n'退出")
                if n == 'n':
                    exit('感谢您的光临')
            else:
                print('请输入正确的商品序号{}-{}'.format(0, len(li)-1))
        elif s == 'q':
            print('欢迎下次再来')
        else:
            print('请输入正确的商品序号{}-{}')

猜你喜欢

转载自www.cnblogs.com/libragyf/p/12176574.html
03-
今日推荐