day2::(python-學習之路)-檔案處理

來源:互聯網
上載者:User

標籤:ems   coding   pre   lis   圖片   選擇   money   close   logs   

需求流程圖:

需求代碼:

#_*_ coding:utf-8 _*_total_money = int(input(‘請輸入您的預算金額:‘))total_list = []while total_money > 0:    f = open(‘shopping_list‘,‘r‘)    print(‘‘‘THE SHOPPING LISTname    money ‘‘‘) #清單模板    shopping_list= {}    for i in f.readlines():        (k,v) = i.strip().split()        shopping_list[k] = v        print(k,v) #列印購物清單    f.close()    min_money = int(min(shopping_list.items(),key=lambda x:x[1])[1]) #取商品的最小金額    if total_money < min_money: #比較輸入金額        print(‘sorry!你的餘額不足,不能購買任何商品!!Bye!~‘)        break    if total_money > 0:        choice_name = input(‘請選擇你要購買的商品名稱:‘)        total_money = total_money - int(shopping_list[choice_name])        if total_money > 0:  #判斷輸入的商品金額是否超出餘額            print(‘您購買的商品是:%s,剩餘金額為:%d‘ %(choice_name,total_money))            next_time = input(‘是否繼續購買:Y/N?‘)            total_list.append(choice_name)            if next_time == ‘y‘:                continue            else:                break        else:            print(‘您的金額不足!‘)            breakprint(‘您購買的商品為:%s‘ %total_list)

 

day2::(python-學習之路)-檔案處理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.