自己编写,还请指正
import random
import time
win_list=[("石头","剪刀"),("布","石头"),("剪刀","布")]
kind_list=['石头','剪刀','布']
chart = {"张旭阳":"123456","程武飞":"456789","王少东":"123789"}
def yonghuming():
count=3
while True:
name = input("请输入用户名:")
if name in chart:
print("用户名正确")
return name
break
else:
if count==1:
print("你登个锤子")
exit()
count -= 1
print("请输入正确用户名,你还有%d次机会" % count)
def mima(name):
count1=3
while True:
password = input("请输入用户名密码:")
if chart[name] == password:
print("欢迎进入人机大战")
renji(name)
break
else:
if count1==1:
print("你玩个锤子")
exit()
count1 -=1
print("密码错误,你还有%d次机会" % count1)
def renji(name):
count=3
print("===================%s,欢迎来到人机大战=========================" % name)
while True:
print("请等待机器人出拳。。。")
time.sleep(1)
print("...")
time.sleep(1)
robot=random.choice(kind_list)
print("机器人已出拳")
people=str(input("请你输入石头/剪刀/布:").strip())
time.sleep(1)
if people in kind_list:
print("您输入的是:",people)
time.sleep(1)
print("机器人输入的是",robot)
if people == robot:
if count==1:
print("game over,请续费")
exit()
count -= 1
print("平局,你还有%d次机会" % count)
elif (people,robot) in win_list:
print("恭喜你,你赢了")
break
else:
if count==1:
print("game over,请续费")
exit()
count -= 1
print("你输了,小垃圾,你还有%d次机会" % count)
else:
if count == 1:
print("game over,请续费")
exit()
count -= 1
print("别瞎输入!你还有%d次机会" % count)
name=yonghuming()
mima(name)