Python 如何在石头剪刀游戏中添加回合选项?

Python 如何在石头剪刀游戏中添加回合选项?,python,Python,我想要一些关于我的石头剪刀游戏代码的帮助。我想添加一个功能,玩家可以选择特定的轮数,而不是预设轮数。我对如何做到这一点很感兴趣,而且我刚刚开始重新学习Python,所以我有点生疏了。非常感谢你!(请忽略拼写;D) 代码: import random#为计算机导入随机模式。 游戏=[“石头”、“布”、“剪刀”]#设置游戏答案。 计数=0#游戏计数设置为零。 分数=0#玩家分数设置为零。 计算机分数=0#计算机分数设置为零。 打印(“欢迎”) 当计数=0时:如果计数为0,则开始游戏。 对于范围(3)

我想要一些关于我的石头剪刀游戏代码的帮助。我想添加一个功能,玩家可以选择特定的轮数,而不是预设轮数。我对如何做到这一点很感兴趣,而且我刚刚开始重新学习Python,所以我有点生疏了。非常感谢你!(请忽略拼写;D)

代码:

import random#为计算机导入随机模式。
游戏=[“石头”、“布”、“剪刀”]#设置游戏答案。
计数=0#游戏计数设置为零。
分数=0#玩家分数设置为零。
计算机分数=0#计算机分数设置为零。
打印(“欢迎”)
当计数=0时:如果计数为0,则开始游戏。
对于范围(3)内的i:#重复3次转弯。
回答=输入(“拾取石头、布或剪刀”)#用户回答。
打印(answer.upper())#打印用户的答案
计算机=随机选择(游戏)#计算机随机选择
打印(“计算机拾取”,计算机)#打印计算机选项。
if answer.upper()=“ROCK”和computer==“ROCK”:#这整套代码设定了什么战胜什么的游戏。
打印(“打成平局!”)#在每个获奖者的回答后打印。
count+=1#count变量增加。
elif answer.upper()=“纸张”和计算机==“纸张”:
打印(“这是一条领带!”)
计数+=1
elif answer.upper()=“剪刀”和计算机==“剪刀”:
打印(“这是一条领带!”)
计数+=1
elif answer.upper()=“纸张”和计算机==“岩石”:
打印(“你赢了!”)
计数+=1
分数+=1#添加用户分数。
elif answer.upper()=“纸”和计算机==“剪刀”:
打印(“你输了!”)
计数+=1
computerscore+=1#添加计算机分数。
elif answer.upper()=“岩石”和计算机==“纸张”:
打印(“你输了!”)
计数+=1
计算机分数+=1
elif answer.upper()=“岩石”和计算机==“剪刀”:
打印(“你赢了!”)
计数+=1
分数+=1
elif answer.upper()=“剪刀”和“电脑”=“石头”:
打印(“丢失!”)
计数+=1
计算机分数+=1
elif answer.upper()==“剪刀”和计算机==“纸”:
打印(“你赢了!”)
计数+=1
分数+=1
如果得分计算机分数:
打印(“您的分数为”,分数)
打印(“计算机系统”,计算机分数)
打印(“您赢了!”)
如果分数==计算机分数:
打印(“您的分数为”,分数)
打印(“计算机系统”,计算机分数)
打印(“这是一条领带!!。”)

在计数=0时更改
当计数

其中
x
是您想要玩的游戏数


此外,我还建议将代码拆分为更多函数,这样会更简洁

更改
,而count==0:
当计数

其中
x
是您想要玩的游戏数


另外,我建议将代码拆分为更多函数,这样会更简洁

创建一个
变量来存储用户输入:

rounds=3
while
循环之前添加以下内容:

user\u input=input('您想玩多少回合?'))
尝试:
轮数=整数(用户输入)
除值错误外:
打印('不是数字')

并将循环的条件更改为“范围内的i”(轮):

创建一个
轮数
变量以存储用户输入:

rounds=3
while
循环之前添加以下内容:

user\u input=input('您想玩多少回合?'))
尝试:
轮数=整数(用户输入)
除值错误外:
打印('不是数字')

并将循环的条件更改为范围内i的
(轮):

您已经阅读了Bobby叔叔您已经阅读了Bobby叔叔
import random                        #imports a random moduel for the computer.
game = ["ROCK", "PAPER", "SCISSORS"]  #sets the game answers.
count = 0                             #game count is set to zero.
score = 0                             #player score is set to zero.
computerscore =0                      #computers score is set to zero.

print ("Welcome")
while count == 0:                     #starts game if count is zero.
  for i in range (3):                  #repeats the turns 3 times.
    answer = input ("Pick rock, paper or scissors.")     #users answer.

    print (answer.upper())                               # prints the users answer
    computer= random.choice(game)                        #computer picks randomly

    print ("Computer picks",computer)                    #prints the computers choice.

    if answer.upper() == "ROCK" and computer == "ROCK":          #This whole set of code sets the game that what beats what.
      print ("Its a tie!")                                       # prints after each response that who won.
      count +=1                                                  #the count variable is increased.

    elif answer.upper() == "PAPER" and computer == "PAPER":
      print ("Its a tie!")
      count +=1

    elif answer.upper() == "SCISSORS" and computer == "SCISSORS":
      print ("Its a tie!")
      count +=1

    elif answer.upper() == "PAPER" and computer == "ROCK":
      print ("You win!")
      count +=1
      score +=1                                                 #user score is added.

    elif answer.upper() == "PAPER" and computer == "SCISSORS":
      print ("You lose!")
      count +=1
      computerscore +=1                                         #computers score is added.

    elif answer.upper() == "ROCK" and computer == "PAPER":
      print ("You lose!")
      count +=1
      computerscore +=1

    elif answer.upper() == "ROCK" and computer == "SCISSORS":
      print ("You win!")
      count +=1
      score +=1

    elif answer.upper() == "SCISSORS" and computer == "ROCK":
      print ("lose!")
      count +=1
      computerscore +=1

    elif answer.upper() == "SCISSORS" and computer == "PAPER":
      print ("You win!")
      count +=1
      score +=1


if score < computerscore:                      #prints out at the end who scored how much and who won.
  print ("Your score is", score)
  print ("Computers socre is",computerscore)
  print ("Computer wins!.")

if score > computerscore:
  print ("Your score is", score)
  print ("Computers socre is",computerscore)
  print ("You win!.")

if score == computerscore:
  print ("Your score is", score)
  print ("Computers socre is",computerscore)
  print ("Its a tie!!.")