Shopping Cart
1List = ["Headset"," Book","MP3","Camare","Condom","Alienware","Iphone7"]2Price = [800,60,300,5000,34,20000,6000]3Basket = []4Salary ="1"5 whileType (Salary)! = Type (1):6 Try:7salary = Int (input ("Please input your salary:"))8 except:9 Print("Please enter number!")Ten whileTrue: One Print("You can buy the following things:") A forIinchRange (1,len (list) +1): - PrintI". ", List[i-1],'\ t', price[i-1]) - whileTrue: theChoice = input ("Please enter the serial number of the item want: ' Q ' is exit!") - ifChoice = ="Q": - Print("You bought something below:",'\ n', Basket,'\ n',"Your balance:", salary,'\ n',"byebye!") - exit () + Try: -Choice =int (choice) + except: A Print("wrong type!") at Continue - ifChoice < 1orChoice >7 : - Print("wrong number!") - Continue - Else: -Price_choice = price[choice-1] in ifPrice_choice >Salary: -differ = Price_choice-Salary to Print("Sorry,you ' re worse than", differ) + Else : -Salary = salary-Price_choice theBasket.append (list[choice-1]) * Print("You got the", list[choice-1]) $ Print("Your balance:", salary)
Python Foundation One