|
初学python小白 猜拳小游戏 求助
代码如下:
import random
print(7*"* ","云 中 游 戏 ",7*"* ")
print("*"," "*9," 剪刀 石头 布"," "*9,"*")
print(20*"* ")
r=input("是否开始猜拳小游戏(y/n):")
#判断是否开始游戏
if r=="y":
player=eval(input("请选择1、剪刀 2、石头 3、布:"))
else :
print("感谢使用本程序,程序已关闭。")
#本来我在这里打上了break ,但一直报错
#
if player==1:
player_action="剪刀"
elif player==2:
player_action = "石头"
elif player==3:
player_action = "布"
else :
player_action = "石头" #如果输入错误,直接默认为出“石头”
#电脑出拳
computer= random.randint(1, 3)
if computer==1:
computer_action="剪刀"
elif computer==2:
computer_action = "石头"
else :
computer_action = "布"
print("您出的是:",player_action,"\n电脑出的是:",computer_action)
#判断输赢,并输出结果
if player==computer:
print("您和电脑打成了平手,请再接再厉!!")
elif (player==1 and computer==2) or (player==2 and computer==3) or (player==3 and computer==1):
print("很遗憾,您输了!请再接再厉!")
else:
print("恭喜您,您赢得了胜利!")
# 怎么才能回到之前继续游戏,这里一直有错误~哭~
r=input("您是否继续游戏y/n:")
求助啊!
|
|