猜年齡函式版day10作業

2022-08-12 12:24:11 字數 1247 閱讀 2022

age = 18

prize_dict = :\n')

print('註冊成功')

break

def login():

'''登入功能'''

print('遊戲登入')

username_inp = input('輸入你的使用者名稱:')

pwd_inp = input('輸入你的密碼:')

with open('username_info.txt','r',encoding='utf8') as fr:

# 使用者資訊切分,比較

for user_info in fr:

username,pwd = user_info.split(':')

if username.strip() == username_inp and pwd.strip() == pwd_inp:

print('登入成功')

else:

print('登入失敗')

def prize():

'''選擇獎品'''

count = 0

while count < 2:

print(f'恭喜你猜對了,請選擇你的獎品,獎品列表如下:\n')

choice = input('請輸入你想要的禮物編號,按q退出')

if choice != 'n':

print(f'恭喜你獲得獎品:')

else:

break

count += 1

def game():

'''猜年齡遊戲'''

count = 0

print('歡迎進入猜年齡遊戲')

while count < 3:

age_inp = input('請輸入年齡:')

if not age_inp.isdigit():

print('格式錯誤')

continue

int_age_inp = int(age_inp)

if int_age_inp < age:

print('猜小了')

elif int_age_inp < age:

print('猜大了')

else:

print('猜對了')

prize()

break

count += 1

register()

login()

game()

day10函式作業詳解

2,寫函式,接收n個數字,求這些引數數字的和。動態傳參 3,讀 回答 中,列印出來的值a,b,c分別是什麼?為什麼?a 10 b 20 def test5 a,b print a,b c test5 b,a print c 4,讀 回答 中,列印出來的值a,b,c分別是什麼?為什麼?a 10 b 2...

猜年齡遊戲函式版

1.在猜年齡的基礎上編寫登入 註冊方法,並且把猜年齡遊戲分函式處理,如 2.登入函式 3.註冊函式 4.猜年齡函式 5.選擇獎品函式 import json real age 18prize list 好迪洗髮水 綠箭俠 小豬佩奇 布娃娃 再來一次 import random user prize ...

day 10 函式高階作業(部分完成)

1.寫乙個匿名函式,判斷指定的年是否是閏年 leap year lambda year 閏年 if year 4 0and year 100 0 or year 400 0else 平年 print leap year 2020 閏年 2.寫乙個函式將乙個指定的列表中的元素逆序 如 1,2,3 3,...