亚洲免费在线视频-亚洲啊v-久久免费精品视频-国产精品va-看片地址-成人在线视频网

您的位置:首頁技術文章
文章詳情頁

Python實現猜年齡游戲代碼實例

瀏覽:30日期:2022-08-01 10:54:52

1. 在猜年齡的基礎上編寫登錄、注冊方法,并且把猜年齡游戲分函數處理,如

2. 登錄函數

3. 注冊函數

4. 猜年齡函數

5. 選擇獎品函數

代碼如下

import jsonreal_age = 18prize_list = [’好迪洗發水’, ’綠箭俠’, ’小豬佩奇’, ’布娃娃’, ’再來一次!’]import randomuser_prize_dict = {}import osdef register(): while True: username = input(’輸入用戶名>>>(q退出):’).strip().lower() if username==’q’:break password = input(’請輸入密碼>>>:’).strip() re_password = input(’請再次確認密碼>>>:’).strip() if not password == re_password: print(’密碼不一致,請重輸!’) continue user_dic = {’name’: username, ’password’: password} json_user_dic = json.dumps(user_dic) with open(f'{username}.txt', ’w’, encoding=’utf-8’)as f: f.write(json_user_dic) f.flush() print(’注冊成功!’) breakdef login(): count = 0 while True: if count == 3: print(’錯誤輸入次數過多!’) break username = input(’請輸入用戶名>>>:’).strip() if not os.path.exists(username + ’.txt’): print(’該用戶不存在!’) continue password = input(’請輸入密碼>>>:’).strip() with open(f'{username}.txt', ’r’, encoding=’utf-8’) as f: user_json_dic = f.read() user_dic = json.loads(user_json_dic) if username == user_dic[’name’] and password == user_dic[’password’]:print(’登錄成功!’)guess_age()break else:print(’用戶名或密碼錯誤!’) count += 1def guess_age(): count = 0 print(’現在進入猜年齡游戲環節.......n’) while True: count += 1 if count == 4: print(’抱歉!你三次都猜錯了!’) again_guess_age = input(’請問是否要繼續猜3次(y繼續,n退出)>>>:’).strip().lower() if again_guess_age == ’y’:count = 0continue break age = input(’請輸入你的年齡>>>:’).strip() if not age.isdigit(): print(’請輸入純數字!’) continue age = int(age) if age > real_age: print(’猜大了!’) elif age < real_age: print(’猜小了!’) else: print(’恭喜你!猜對了!n’) choice_prize() breakdef choice_prize(): count = 1 print(’進入抽獎環節.....,您共有兩次機會!n 獎品如下:’) while True: for index, prize in enumerate(prize_list, 1): print(index, prize) choice = input(’請按下按鈕y隨機選擇獎品>>>:’).strip().lower() if not choice == ’y’: print(’非法輸入!’) continue prize_choice = random.randint(1, 15) if prize_choice in [6, 7, 8]: prize_choice = 4 elif prize_choice in [9, 10, 11, 12, 13, 14, 15]: prize_choice = 5 prize = prize_list[prize_choice - 1] if prize in user_prize_dict: user_prize_dict[prize] += 1 else: user_prize_dict[prize] = 1 print(f’本次獲得獎品為:{prize},您還有{2-count}次機會!n’) if count == 2: if user_prize_dict.get(’再來一次!’):user_prize_dict.pop(’再來一次!’) print(f’總共獲得的獎品為:{user_prize_dict}’) break count += 1user_func_dic = { ’1’: register, ’2’: login,}while True: print(’’’ 先注冊,登陸后才能玩猜年齡游戲哦! 1. 注冊 2. 登錄 ’’’ ) choice = input(’請選擇功能編號(q退出)>>>:’).strip().lower() if choice == ’q’ : break if not choice in user_func_dic: print(’錯誤輸入’) continue user_func_dic.get(choice)()

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 欧美一区二区在线观看免费网站 | 欧美亚洲黄色 | 欧美精品99久久久久久人 | 亚洲成人免费观看 | 亚洲精品午夜在线观看 | 日本三级香港三级乳网址 | 国产末成年女噜噜片 | 91天堂网 | 亚洲第99页| 欧美特级一级毛片 | 久久精品爱国产免费久久 | 国产成人精品免费视频 | 黄网在线观看免费网站台湾swag | 国产成人免费网站在线观看 | 成年女人免费视频播放成年m | 国产亚洲精品国产 | 久久精品国产这里是免费 | 全部毛片| 国产精品色午夜视频免费看 | 久久国产亚洲欧美日韩精品 | 中文三 级 黄 色 片 | 中文字幕在线视频网站 | 久久综合一区二区三区 | 国产成人综合久久亚洲精品 | 久久精品国产第一区二区 | 亚洲mm8成为人影院 亚洲m男在线中文字幕 | 亚洲伦乱 | 在线免费一级片 | 日本成人一级片 | 色综合色狠狠天天久久婷婷基地 | 久草首页在线 | 国产成人一区二区三区免费观看 | 欧美精品一区二区三区视频 | a级在线观看视频 | 亚洲图片偷拍区 | 欧美成人伊人十综合色 | 手机看片国产在线 | 久久久久久久99视频 | 韩国理伦一级毛片 | 亚洲视频 欧美视频 | 国产精品资源手机在线播放 |