首页 > 其他 > 详细

GItHub base 03-

时间:2020-01-10 16:18:50      阅读:82      评论:0      收藏:0      [点我收藏+]
"""  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(‘请输入正确的商品序号{}-{}‘)

GItHub base 03-

原文:https://www.cnblogs.com/libragyf/p/12176574.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!