Guess Age v2.0

'' '
User login, only three chances

Given the age of the user can guess the age of three

Age guessed, allowing users to choose two rewards, enter an invalid character, allowing them to choose whether or not to gift

After the user selects the award twice to exit, select another occasion after the first prompt
'' '

Basic information is defined

user_info_dict = {
'james':'007',
'thor':'001',
'ironman':'002',
'spiderman':'003'
}
prize_dict = {'0': 'durex', '1': 'okamoto', '2': 'Jissbon'}
login_count = 0
guess_count = 0
age = 30

Enter the user name and password

while 1:
user_name = input("login the user'name:")
user_pwd = input("login the password:")
if login_count == 2:
print('error too many times.')
break

if (user_name in user_info_dict) and (user_info_dict.get(user_name) == user_pwd):
    print('start\n')
    break
else:
    login_count += 1
    print('name or password error')
    continue

guess_count the while <. 3:
# added to the input digital guessing
the while. 1:
guess_age = INPUT ( 'My GUESS Age:' Strip () the lstrip ( '0')..)
IF guess_age.isdigit ():
BREAK
the else:
Print ( ' fucking number please! ')

guess_age_int = int(guess_age)
guess_count += 1

# 核心判断
if guess_age_int > age:
    print('too old')
elif guess_age_int < age:
    print('too young')
else :
    print('bingo')
    print(prize_dict)
    prize_count = 0

    #选择奖励
    while prize_count < 2:
        prize_select = input('select a prize:')
        prize_count += 1
        if prize_select in prize_dict:
            print(f'you got a {prize_dict[prize_select]}')
        else:
            print('want to give up the prize?')
            choice = input('yes or no:')
            if choice == 'no':
                prize_count = 0
                continue
            else:
                break
        print('one more prize')
    break

Guess you like

Origin www.cnblogs.com/agsol/p/11529643.html