在家无聊便写了这个小游戏,
升级版猜数字游戏添加了输入账号和密码的功能,适合新手参考!
import random
ran = str(random.randint(1,10))
# print(ran)
markers = 0
markers1 = 0
markers2 = 0
list_name = ['xjh','XJH']
list_password = ['123',]
print('''
*********************************************
Welcome to the number guessing game
>>> Producer:どうでもいい菌 <<<
*********************************************
''')
#账号密码
while True :
information = input('Please log in first.\nUse existing account (Y / N):')
if information == 'Y':
init_usrname = input('Please enter initial username:')
init_password = input('Please enter initial password:')
print('usrname{},password{}'.format(init_usrname, init_password))
break
if information == 'N':
while True:
usr = input('enter username:')
if usr in list_name:
while markers < 3:
password = input('enter password:')
if password in list_password:
print('Success Login!')
markers1 = 1
break
else:
markers += 1
if markers <= 2:
print('Wrong Password,enter again!')
if markers1 == 1:
break
print('You have tried three times,login again!')
else:
print('Wrong Username,enter again!')
if markers1 == 1:
break
else:
print('Input error, invalid.')
#游戏主体
while True :
print('>>>Game start<<
while markers2 <= 3:
num = input('Please enter random between (1-10):')
if num > ran:
print("It's too big.")
if num < ran:
print("It's too small.")
if ran == num:
print('Correct.\nGame over.')
break
else:
markers2 += 1
if markers2 > 3:
print('You ran out of opportunities.Game over.')
play_again = input('Do you want to do it again (Y / N):')
if play_again == 'N':
break
在终端上运行了一下,还可以
密码输错会指出:
写的时间比较短,可能有一些不足的地方,希望大佬们指出!
谢谢!