day2_作业1(购物车)

2018-06-18 02:43:15来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

#!/usr/local/bin/python3
# -*- coding:utf-8 -*-

balance=input("\033[36;1mPlease input your salary:\033[0m")
Merchandise_list=[[1,'Mac pro',16888],[2,'Iphone x',7888],[3,'Ps4 pro',4000]]
shopping_list=[]
if balance.isdigit():
    balance = int(balance)
    while True:
        print('\033[31;1mMerchandise list:\033[0m')
        for x in Merchandise_list:
            print(x)
        num=input("which one do you want?-->")
        if num.isdigit():   #判断输入类型是否是数字类型
            if int(num)<=len(Merchandise_list) and int(num)>0:
                if balance>=Merchandise_list[int(num)-1][2]:
                    balance-=Merchandise_list[int(num)-1][2]
                    shopping_list.append(Merchandise_list[int(num)-1])
                    print("your balance:\033[31;1m%s\033[0m"%(balance)) #设置字体颜色为红色,绿色为32
                else:
                    print("your balance:\033[31;1m%s\033[0m"%(balance))
                    print("\033[31;1myour balance was inadequate!\033[0m")
                    continue
            else:
                print("\033[41;1mthis product was not exist!\033[0m")
                print("your balance:\033[31;1m%s\033[0m" % (balance))
        elif num=='q':
            print("\033[43;1m----------your shopping list:----------\033[0m")
            for x in shopping_list:
                print("\033[35;1m%s\033[0m"%(x))
            print("your balance:\033[31;1m%s\033[0m" % (balance))
            exit()
        else:
            print("\033[41;1minvalid input!\033[0m")
            print("your balance:\033[31;1m%s\033[0m" % (balance))
else:
    print("\033[41;1minvalid input!\033[0m")
    exit()

  

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Python-Flask框架之——图书管理系统 , 附详解源码和效果图 !

下一篇:Python爬虫 - 爬取百度html代码前200行