日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python中对列表和循环使用的小练习

發布時間:2024/9/5 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python中对列表和循环使用的小练习 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#author devilfproduct_list = [('iphone',5800),('Mac Pro',9800),('Bike',800),('Watch',10000),('Coffee',123) ] shop_list = [] salary = input('pls enter your salary: ')if salary.isdigit(): #判斷是否為整形,否則會退出salary = int(salary)while True:for index,info in enumerate(product_list): #打印列表 # print(product_list.index(info),info)print(index,info)user_choice = input('pls enter what you buy\n>>>: ') #輸入要購買的商品 編號if user_choice.isdigit(): #再判斷下輸入的是否是數字,否則退出user_choice = int(user_choice)if user_choice <= len(product_list) and user_choice >= 0: #判斷輸入的編號是否在商品列表的編號范圍內p_item = product_list[user_choice] #取出編號對應的商品名稱if p_item[1] <= salary: #判斷改商品的價格是否在工資范圍內shop_list.append(p_item) #如果在工資范圍內,購買!salary -= p_item[1] #總工資便會減少對應的錢print('Added %s into shopping cart,your current balance is %s' %(p_item,salary))else:print('your current balance is %s ,now is not enough' % (salary))else:print('product %s is not exist!' % user_choice )elif user_choice == 'q': #如果輸入的是 'q',便會退出print('-------------shopping list------------')for p in shop_list:print(p)print('quit.....,your current money: ',salary)exit()else:print('Invalid option')

?

轉載于:https://www.cnblogs.com/Devilf/p/8044713.html

總結

以上是生活随笔為你收集整理的python中对列表和循环使用的小练习的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。