找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 396|回复: 0

[求助] 自学小白求助

1

主题

1

帖子

1

积分

贫民

积分
1
wanyouyinli 发表于 2022-11-25 18:39:07 | 显示全部楼层 |阅读模式
初学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:")
求助啊!

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表