Python猜拳游戏循环的代码如下:# 定义变量
Python猜拳游戏循环的代码如下:
# 定义变量
player_score = 0
computer_score = 0
# 开始游戏
while True:
# 玩家出拳
print("请出拳:1.剪刀 2.石头 3.布")
player = int(input("请输入数字:"))
# 计算机出拳
import random
computer = random.randint(1, 3)
# 判断胜负
if (player == 1 and computer == 2) or (player == 2 and computer == 3) or (player == 3 and computer == 1):
print("你输了!")
computer_score += 1
elif player == computer:
print("平局!")
else:
print("你赢了!")
player_score += 1
# 显示得分
print("你的得分:%d,电脑的得分:%d" % (player_score, computer_score))
# 判断游戏是否结束
if player_score == 3 or computer_score == 3:
if player_score > computer_score:
print("游戏结束,你赢了!")
else:
print("游戏结束,你输了!")
break
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(55条)