Python简单购物车程序练习

wages = int(input('请输入工资:'))
Item_list = ('0-雪糕 2元/个', '1-饮料 3元/瓶', '2-小吃 1元/袋', '3-方便面 5元/桶', '7-物品列表', '8-购物车', '9-退出')
My_item = []
for i in Item_list:
    print(i)
while True:
    Item_Num = int(input('请输入商品编号:'))
    if Item_Num == 9:
        break
    elif Item_Num == 0:
        if wages >= 2:
            wages = wages - 2
            print('购买了雪糕,当前余额:', wages)
            My_item.append('雪糕')
            print('---------------------------')
        else:
            print('余额不足')
            print('购物车内的物品为:', My_item)
            print('---------------------------')
            break
    elif Item_Num == 1:
        if wages >= 3:
            wages = wages - 3
            print('购买了饮料,当前余额:', wages)
            My_item.append('饮料')
            print('---------------------------')
        else:
            print('余额不足')
            print('购物车内的物品为:', My_item)
            print('---------------------------')
            break
    elif Item_Num == 2:
        if wages >= 1:
            wages = wages - 1
            print('购买了小吃,当前余额:', wages)
            My_item.append('小吃')
            print('---------------------------')
        else:
            print('余额不足')
            print('购物车内的物品为:', My_item)
            print('---------------------------')
            break
    elif Item_Num == 3:
        if wages >= 5:
            wages = wages - 5
            print('购买了方便面,当前余额:', wages)
            My_item.append('方便面')
            print('---------------------------')
        else:
            print('余额不足')
            print('购物车内的物品为:', My_item)
            print('---------------------------')
            break
    elif Item_Num == 7:
        for i in Item_list:
            print(i)
    elif Item_Num == 8:
        print('购物车内的物品为:', My_item)
        print('---------------------------')
    else:
        continue

发表评论

您的电子邮箱地址不会被公开。

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据