码迷,mamicode.com
首页 > 编程语言 > 详细

python基础一

时间:2017-03-29 01:19:02      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:exce   int   cond   serial   type   iphone   tin   item   ==   

购物车

 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基础一

标签:exce   int   cond   serial   type   iphone   tin   item   ==   

原文地址:http://www.cnblogs.com/kimyeee/p/6637622.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!