女友用python寫的充值卡沖花費的代碼


女友最近在學習python ,於是我拿當初我們學習C語言的課程設計 手機號充花費功能讓她嘗試着做一下,在分析完思路和幫助改錯的情況下代碼如下:

python2.7.17 環境

#/usr/bin/python
#-- coding:UTF-8 --
phone_list={"123":100}
phonemima_list={'123':'11'}
charge_list={"456789":"123456"}
charge_fee={"456789":20}
num=str(input('請輸入你的手機號:'))

if num in phone_list:
    mima=str(input('請輸入你的手機密碼:'))
    if mima == phonemima_list[num]:
        print('你的余額為'+str(phone_list[num]))
        while True:
            option = str(input("充值請輸入1,退出請輸入2\n"))
            if option == '1':
                kahao=str(input('請輸入充值卡號:'))
                if kahao in charge_list:
                    chongzhimima=str(input('請輸入充值密碼:'))
                    if chongzhimima==charge_list[kahao]:
                        print("充值卡內余額"+str(charge_fee[kahao]))
                        chongzhi_money=int(input('本次充值:'))
                        while chongzhi_money> charge_fee[kahao]:
                            print("不能充值超過余額的金額")
                            chongzhi_money=int(input('本次充值:'))
                        phone_list[num]=phone_list[num]+chongzhi_money
                        charge_fee[kahao]=charge_fee[kahao]-chongzhi_money
                        print('話費余額還有'+str(phone_list[num]))
                        if charge_fee[kahao]==0:
                            del charge_list[kahao]
                            print('充值卡作廢')
                        else:
                            print('充值卡余額還有'+str(charge_fee[kahao]))
                    else:
                        print('密碼錯誤')
                else:
                    print('卡號不存在')
            elif option == '2':
                break
            else:
                continue
    else:
        print('密碼錯誤')
else:
    print('手機號不存在')

這里面簡單的記錄手機號話費服務密碼,以及充值卡密碼余額等信息,然后處理數據。

希望她有所收獲,我也共同學習


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM