I guess the age of an upgraded version of the game, join login, registration

Guess the age of an upgraded version of the game, join login, registration
Have an account login.txt content nick: 123 | sean: 456 | tank: 789
No account is registered
reference https://www.cnblogs.com/caicairui/p/7520037. html

!/bin/bash/env python

-- coding:utf-8 --

the Login DEF (username, password):
"" "
login password for the user name
: param username: Username
: param password: password
: return: True, user authentication is successful; False, validation fails
" ""
with Open ( 'the Login .txt ',' R & lt ', encoding = "UTF-. 8") AS F:
for USER_INFO in F:
USER_INFO = user_info.strip (' \ n-')
user_info_list = user_info.split (' | ') slicing string # list is directly
MSG = dict ()
for MSGA in user_info_list:
MSGA = msga.split ( ':')
K = MSGA [0]
V = MSGA [. 1]
MSG [K] = V
Print (MSG)
IF username in MSG. Keys () and password == msg [username]:
Print ( 'successful landing')
return True

def register(username, password):
"""
注册用户
:param username: 用户名
:param password: 密码
:return: True,注册成功
"""
with open('login.txt', "a", encoding="utf-8") as f:
temp = "\n" + username + ":" + password
f.write(temp)
return True

user_exist DEF (username):
"" "
Check if the user already exists
: param username: Username
: return: True, the user name already exists; False, the user name does not exist
" ""
with Open ( 'login.txt', " R & lt ", encoding =" UTF-. 8 ") AS F:
for F in Line:
Line = line.strip ()
line_list line.split = (" $ ")
IF username == line_list [0]:
return True
return False

main DEF ():
Print ( "Welcome NICK system")
InP = the INPUT ( "1: landing; 2: Registration")

user = input("请输入用户名:")
pwd = input("请输入密码:")

if inp == "1":
    is_login = login(user, pwd)
    if is_login:
        print("登录成功")
    else:
        print("登录失败")
elif inp == "2":
    is_exist = user_exist(user)
    if is_exist:
        print("用户已经存在,无法注册")
    else:
        result = register(user, pwd)
        if result:
            print("注册成功")
        else:
            print("注册失败")

main()

price_choice1 DEF ():
F = Open ( 'price.txt', 'R & lt', encoding = 'UTF8') # price.txt why the lower right corner of encoding, the encoded encoding Why
price_dict reached, f.read = ()
price_dict = the eval (price_dict ) # type: dict # Get prizes dictionary #eval achieve mutual transformation between the function list, tuple, dict string
f.close ()
price_self = dict ()
for K, V in price_dict.items ():
Print (F 'No prizes: {V} {K}')
# acquired prize two cycles
for I in Range (2):
price_y = INPUT (F 'please press "Y or y" dial rotational {chr (9803)}:' ) .lower ()
! = IF price_y 'the y-':
Print ( "!! Congratulations, you've got a prize, the prize is empty and enter 'the Y-or the y-'")
the Continue

    # 控制获奖奖品的频率
    price_choice = random.randint(0, 10000)

    if price_choice > 0 and price_choice < 9900:
        price_choice = 6
        print('恭喜你, 下次一定有好东西!!', end=' ')
    else:
        price_choice = price_choice % 7

    if price_choice not in price_dict:
        print('你想多了吧!')
    else:
        price_get = price_dict[price_choice]
        print(f'恭喜中奖:{price_get}')

        if price_self.get(price_get):
            price_self[price_get] += 1
        else:
            price_self[price_get] = 1
        print(f'恭喜你获得以下奖品:{price_self}')

Random Import
Age = random.randint (18, 60) # random digit, 18-60 years old
count = 0 # count
the while COUNT <3:
COUNT + = 1
inp_age the INPUT = ( 'Please enter the age you want to guess:' )
# determine if it is pure digital
iF not inp_age.isdigit ():
Print ( 'shout out things you idiot')
the Continue
inp_age = int (inp_age)
# screening age range
iF inp_age> 60 or inp_age <18:
Print ( 'good title, 18-60 years old, you are the One ')
the Continue
# core logic
IF Age == inp_age:
Print (' guessed, please choose your prize ')
price1a = price_choice1 () # prizes to function
Print (price1a)
BREAK
elif Age> inp_age:
Print ( 'small guess')
elif Age <inp_age:
Print ( 'big guess')
Continue

Guess you like

Origin www.cnblogs.com/abdm-989/p/11323519.html