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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

在猜年龄的基础上编写登录、注册方法,并且把猜年龄游戏分函数处理

發(fā)布時間:2024/4/17 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在猜年龄的基础上编写登录、注册方法,并且把猜年龄游戏分函数处理 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
''' 在猜年齡的基礎上編寫登錄、注冊方法,并且把猜年齡游戲分函數(shù)處理,如 2. 登錄函數(shù) 3. 注冊函數(shù) 4. 猜年齡三次函數(shù) 5. 選擇三次獎品函數(shù) ''' import random def username_pwd():username=input('請輸入你的用戶名:').strip()pwd=input('請輸入你的密碼:').strip()return username,pwd def register():count=0while count<2:username, pwd = username_pwd()pwd_re = input('請再次輸入你的密碼:').strip()if pwd_re == pwd:print(f'用戶{username}注冊成功')with open('user_info.txt', 'a', encoding='utf8')as fa:fa.write(f'{username}:{pwd}\n')fa.flush()breakelse:count+=1print(f'用戶{username}兩次密碼不正確:') def login():while True:username,pwd=username_pwd()user_info=f'{username}:{pwd}\n'with open('user_info.txt','r',encoding='utf8')as fr:user_dict=fr.read()if user_info in user_dict:print(f'用戶{username}登錄成功:')breakelse:print(f'用戶{username}登錄失敗:') def guess_age():count=0while count<3:age=random.randint(18,50)chose_age=input('猜年齡游戲開始,請輸入你的年齡或q退出:').strip()if chose_age=='q':breakif not chose_age.isdigit():print('請輸入整數(shù)字:')continuechose_age=int(chose_age)if chose_age>50 or chose_age<18:print('請輸入大于18而小于50之間的整數(shù):')continueif chose_age>age:count+=1print('猜大了')elif chose_age<age:count+=1print('猜小了')else:print('恭喜你猜對了')break def chose_prize():prize={'1':'布娃娃','2':'手機','3':'電腦','4':'充氣娃娃','5':'狗糧',}prize_dict={}count=0while count<3:for k ,v in prize.items():print(k,v)choice = input('請選擇三次你的獎品或q退出:').strip()if choice == 'q':breakif choice not in prize:print('請輸入正確的數(shù)字:')continueprize_info = prize[choice]print(f'你得到的獎品是:{prize_info}')if prize_info in prize_dict:count+=1prize_dict[prize_info] += 1else:count+=1prize_dict[prize_info] = 1print(f'你得到的總獎品是{prize_dict}')func_msg={'1':register,'2':login,'3':guess_age,'4':chose_prize, } while True:print('''1 注冊2 登錄3 猜年齡游戲4 選擇獎品q 退出''')choice=input('請選擇功能或q退出:').strip()if choice=='q':breakif not choice.isdigit:print('請輸入數(shù)字:')continueif choice not in func_msg:print('請輸入正確的數(shù)字:')continuefunc_msg[choice]()

轉(zhuǎn)載于:https://www.cnblogs.com/jinhongquan/p/11550887.html

總結(jié)

以上是生活随笔為你收集整理的在猜年龄的基础上编写登录、注册方法,并且把猜年龄游戏分函数处理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。