import random
def quan():
try:
guess=int(input("输入你要出的拳:石头(1)/剪刀(2)/布(3)/退出(4)>>>"))
if guess <=4 and guess >=1:
return guess
else:
print("输错了,请重新输>>>")
s=quan()
return s
except ValueError:
print("输错了,请重新输>>>")
s=quan()
return s
if __name__ == '__main__':
guess_dic={1:"石头",2:"剪刀",3:"布"}
while True:
guess=random.randint(1,3)
guess_vs=quan()
if guess==guess_vs:
print("平局。你出拳{0},电脑出拳{1}".format(guess_dic.get(guess_vs),guess_dic.get(guess)))
elif guess_vs==4:
print("退出游戏。")
break
elif (guess_vs==1 and guess == 2)or (guess_vs==2 and guess == 3)or (guess_vs==3 and guess == 1):
print("赢了!你出拳{0},电脑出拳{1}".format(guess_dic.get(guess_vs),guess_dic.get(guess)))
else:
print("输了!你出拳{0},电脑出拳{1}".format(guess_dic.get(guess_vs),guess_dic.get(guess)))
Python接口自动化测试框架(练习篇)作业2 猜拳
最新推荐文章于 2024-05-27 15:35:10 发布