Flow chart
Code Program
saving = Int (input (' Please enter your salary: '))
shopping = [' iphone ', 5800],[' mx6 ', 2000],[' Pythonbook ', 80],[' surface ', 12000],[' coffe ', []] #商品列表
count = 0 #商品列表编号
shoppinglist = [] #存储购买的商品
For I in shopping: #给商品列表加上标签1 2 ....
Count +=1
print (count,i)
print (' Press-1 to exit the purchase ') #退出购物循环
While True:
number = Int (input (' Please enter the Product ID: '))
if saving <= 0 or number = =-1: #检查余额和退出命令
Break
Elif number not in range (1,len (shopping) +1): #检查输入的合法性
print (' input error, new input ')
Continue
print (number,shopping[number-1][1]) #提示选择的商品编号和价格
if shopping[number-1][1] < saving: #商品的价值与输入的工资进行比较
print (Shopping[number-1:number]) #提示选择的商品价格
shoppinglist.append (Shopping[number-1:number]) #已经选好的商品加入购物车
Saving-= shopping[number-1][1] #余额等于工资减去购买商品的价价格
print (' balance ', saving) #提示余额
Else:
print (' Boy you pay less, buy a little cheaper ') #余额不足, warm tips
For i in shoppinglist: #打印购买成功的商品
print (i)
print (' balance ', saving) #打印余额
Summary points:
1. Flowchart can help me understand the sequence of programming logic more quickly
2. Consider that the product list is dynamic and can be added or deleted
3. Consider the legality of user input
4. Consider whether the user input is repeated input
5. Record the item selected by the user and indicate the remaining balance
6. User exit, print the product information and balance that the user chooses good
Python applet--shopping