首页 > 代码库 > python基础一
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基础一
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。