day2_作业1(购物车)

Posted 漫漫长路

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了day2_作业1(购物车)相关的知识,希望对你有一定的参考价值。

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

balance=int(input("Please input your salary:"))
Merchandise_list=[[1,‘Mac pro‘,16888],[2,‘Iphone x‘,7888],[3,‘Ps4 pro‘,4000]]
shopping_list=[]
while True:
    print(‘Merchandise list:\n‘)
    for x in Merchandise_list:
        print(x)
    num=input("which one do you want?-->")
    if num!=‘q‘:
        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:",balance)
        else:
            print("your balance:",balance)
            print("your balance was inadequate!")
    else:
        print("your shopping list:", shopping_list)
        print("your balance:", balance)
        print("Looking forward to your next visit~")
        break

  

以上是关于day2_作业1(购物车)的主要内容,如果未能解决你的问题,请参考以下文章

Python学习day2作业总结

Day2作业:购物商城

老男孩Day2作业:购物车程序

Python3.5 Day2作业:购物车程序

python day2 购物车作业

day2购物商城