Requirements Flowchart:
Requirements Code:
#_*_ coding:utf-8 _*_Total_money = Int (input ('Please enter your budget amount:')) Total_list= [] whileTotal_money >0:f= Open ('shopping_list','R') Print(" "The shopping listname money" ")#Inventory Templateshopping_list= {} forIinchF.readlines (): (k,v)=I.strip (). Split () Shopping_list[k]=vPrint(K,V)#Print a shopping listf.close () Min_money= Int (min (Shopping_list.items (), key=LambdaX:X[1]) [1]) #取商品的最小金额ifTotal_money <Min_money: #比较输入金额Print('sorry! your balance is insufficient, can not buy any goods!! bye! ~') Break ifTotal_money >0:choice_name= Input ('Please select the name of the product you want to buy:') Total_money= Total_money-Int (shopping_list[choice_name])ifTotal_money >0: #判断输入的商品金额是否超出余额Print('the item you purchased is:%s, the remaining amount is:%d'%(Choice_name,total_money)) Next_time= Input ('do you want to continue buying: y/n? ') total_list.append (choice_name)ifNext_time = ='y': Continue Else: Break Else: Print('Your amount is not enough! ') BreakPrint('the item you purchased is:%s'%total_list)
Day2:: (python-Learning Path)-Document processing