python基础一

Posted

tags:

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

购物车

 1 list = ["Headset","Book  ","Mp3   ","Camare","Condom","Alienware","Iphone7"]
 2 price = [800,60,300,5000,34,20000,6000]
 3 basket = []
 4 salary ="1"
 5 while type(salary) != type(1):
 6     try:
 7        salary = int(input("please input your salary:"))
 8     except:
 9         print("Please enter number !")
10 while True:
11     print("You can buy the following things:")
12     for i in range(1,len(list)+1):
13         print (i,". ",list[i-1],\t,price[i-1])
14     while True:
15         choice = input("please enter the serial number of the item you want: ‘q‘ is exit!")
16         if choice == "q":
17             print("You bought something below:", \n,basket, \n, "your balance:", salary, \n, "byebye!")
18             exit()
19         try:
20             choice = int(choice)
21         except:
22             print("Wrong type!")
23             continue
24         if choice < 1  or choice >7 :
25             print("Wrong number!")
26             continue
27         else:
28             price_choice = price[choice-1]
29             if price_choice > salary:
30                 differ = price_choice - salary
31                 print("Sorry,You‘re worse than", differ)
32             else :
33                 salary = salary - price_choice
34                 basket.append(list[choice-1])
35                 print("you got the",list[choice-1])
36                 print("your balance:",salary)

 

以上是关于python基础一的主要内容,如果未能解决你的问题,请参考以下文章

python之基础篇——模块与包

0基础学Python未来5~10年新一代毕业生职场人的新风向,学Python并非程序员的专属。

开发工具 | 即将jupyter的新一代notebook

Flask 编写http接口api及接口自动化测试

python基础--ASCII码

Python基础-----random随机模块(验证码)