zoukankan      html  css  js  c++  java
  • Python3中实现简单的购物车程序

    product_list = [
        ('iphone',5800),
        ('imac',15800),
        ('watch',9800),
        ('cloth',550),
        ('coffe latee',35),
        ('body call',200),
    ]
    shopping_list = []
    salary = input('please input your salary:').strip()
    if salary.isdigit():
        salary = int(salary)
        while True:
            for index,item in enumerate(product_list):
                print(index,item)
            user_choice = input('please input your choice'.center(50,'*')).strip()
            if user_choice.isdigit():
                user_choice = int(user_choice)
                if 0 <= user_choice < len(product_list):
                    buy_item = product_list[user_choice]
                    if salary >= buy_item[1]:
                        shopping_list.append(buy_item)
                        salary -= buy_item[1]
                        print('you have put the 33[32;1m"%s" 33[0min your cast,your balance is33[31;1m %d33[0m'%(buy_item[0],salary))
                    else:
                        print('33[41;1mfuck off!!! you can`t afford it!!! your balance is %s !!!33[0m'%(salary))
                else:
                    print('product code [%s] is not exist!!!'%user_choice)
            elif user_choice == 'q' or user_choice == 'quit':
                print('you have buyed:'.center(50,'-'))
                print(shopping_list)
                exit()
            else:
                print('Invalid choice!!!')
    

      

  • 相关阅读:
    BZOJ2738 矩阵乘法
    BZOJ3585 mex
    BZOJ1930 [Shoi2003]pacman 吃豆豆
    BZOJ3858 Number Transformation
    vue2.0学习小列子
    vue2.0 tab切换几种方式
    github学习
    只有自己看的懂的vue 二叉树的3级联动
    vuex学习
    vue2.0 MintUI安装和基本使用
  • 原文地址:https://www.cnblogs.com/hjc4025/p/6485482.html
Copyright © 2011-2022 走看看