day 10宿題
4236 ワード
年齢のアップグレード版を当てます
'''
1. ,
2.
3. ,
4.
'''
import random
prize_dict = {
'0': ' ',
'1': ' ',
'2': '《 python》',
'3': ' ',
'4': 'iphoneX',
'5': ' ',
'6': ' ',
'7': ' ',
'8': ' '
}
prize_cart = dict() #
def register():
""" """
print(' !')
count = 0
while count < 3:
#
username_inp = input(' :').strip()
pwd_inp = input(' :').strip()
re_pwd_inp = input(' :').strip()
#
if re_pwd_inp != pwd_inp:
print(' ')
count += 1
continue
# ,
with open('userinfo.txt', 'a', encoding='utf-8') as fa:
with open('userinfo.txt', 'r', encoding='utf-8') as fr:
data = fr.read()
if username_inp in data:
print(f' {username_inp} , ')
count += 1
continue
fa.write(f'{username_inp}:{pwd_inp}
')
print(' ')
break
def login():
""" """
print(' 。。。')
count = 0
while count < 3:
#
username_inp = input(' :').strip()
pwd_inp = input(' :').strip()
#
with open('userinfo.txt', 'r', encoding='utf-8') as fr:
for i in fr:
i = i.strip('
')
username, pwd = i.split(':')
if username_inp == username and pwd_inp == pwd:
print(' ')
count = 3
return guess_age()
else:
print(' ')
count += 1
def select_prize():
""" """
#
print(' :
')
for i, j in prize_dict.items():
print(f' :{i} {j}')
for i in range(2): #
prize_choice = input(' , q ').strip()
if prize_choice == 'q':
break
if prize_choice not in prize_dict:
print(' ')
else:
prize_get = prize_dict[prize_choice]
print(f' :{prize_get}')
#
if prize_get in prize_cart:
prize_cart[prize_get] += 1
else:
prize_cart[prize_get] = 1
print(f' :{prize_cart}')
def guess_age():
""" """
print(' , 18-80')
age = random.randint(18, 80)
print(f' :{age}')
count = 0
while count < 3:
count += 1
age_inp = input(' :').strip()
if not age_inp.isdigit(): #
print(' , ')
continue
age_inp = int(age_inp)
#
if age_inp > 80 or age_inp < 18:
print(' ')
continue
#
if age_inp == age:
print(' ')
return select_prize()
elif age_inp < age:
print(' ')
else:
print(' ')
continue
func_msg = '''
1.
2.
3.
'''
func_dict = {
'1': register,
'2': login,
'3': guess_age
}
print(func_msg)
#
while True:
choice = input(' :').strip()
if not choice.isdigit():
print(' , ')
continue
elif int(choice) > len(func_dict.keys()):
print(' , ')
continue
else:
break
func_dict.get(choice)()