Python 基本变量不添加!!!(我守则的一部分) number=1 p1=0 p2=0 如果是平局,则数字

Python 基本变量不添加!!!(我守则的一部分) number=1 p1=0 p2=0 如果是平局,则数字,python,variables,Python,Variables,,则无需更新分数。然而: number = 1 p1 = 0 p2 = 0 while number <5: gametype = input("Do You Want To Play 1 Player Or 2 Player") if gametype == "2": player1areyouready = input("Player 1, Are You Ready? (Yes Or No)") #Asking If Their Ready if player

,则无需更新分数。然而:

number = 1

p1 = 0
p2 = 0

while number <5:
  gametype = input("Do You Want To Play 1 Player Or 2 Player")
  if gametype == "2":
    player1areyouready = input("Player 1, Are You Ready? (Yes Or No)") #Asking If Their Ready
  if player1areyouready == "yes": #If Answer is Yes
    print ("Great!")
  else: #If Answer Is Anything Else
    print ("Ok, Ready When You Are! :)")
  player2areyouready = input("Player 2, Are You Ready? (Yes Or No)") #Asking If Their Ready
  if player2areyouready == "yes":
   print ("Great, Your Both Ready!") #If Both Are Ready
  else:
    print ("Ok, Ready When You Are! :)")

  print ("Lets Get Right Into Round 1!") #Start Of Round 1
  game1 = input("Player 1, What Is Your Decision? (Rock, Paper or Scissors?) (No Capitals Please)") #Asking Player 1 For their Decision
  game2 = input("Player 2, What Is Your Decision? (Rock, Paper or Scissors?) (No Capitals Please)") #Asking Player 2 For Their Decision

  if game1 == game2:
   print("Tie!") 
   p1 + 0
   p2 + 0
   print ("Player 1's Score Currently Is...")    
   print (p1)

   print ("Player 2's Score Currently Is...") 
   print (p2) #I'm Programming A Rock, Paper Scissors Game

当前未更新分数,因为执行
p1+分数
不会更新
p1
的值。你需要重新分配给它。所以,当我在空闲时间运行你的代码时,我会遇到各种各样的问题。撇开这一点不谈,如果你所要做的只是把一个变量和它的所有数字相加,那么你就可以这样做了

if game1 != game2:
    p1 = p1 + score # Replace score with a number or assign score a value
    p2 = p2 + score
所有这些操作都是将1添加到变量中的当前数字


应该很简单。

你没有在分数上添加任何内容。首先,你关于分数的唯一陈述是一个表达式,而不是一个作业。您需要通过将结果存储回变量中来保留该值,例如

# Put this at the end of the if statement where player one is the winner.
p1 += 1 
# Put this at the end of the if statement where player two is the winner.
p2 += 1
你可以缩短到

number = number + 1
其次,将0添加到p1和p2。即使存储结果,值也不会更改


修理

您需要确定哪个玩家获胜,然后增加该玩家的分数。我不会为你写详细的代码,但是考虑一下:

number += 1

你知道这是怎么回事吗?仅当玩家赢得一轮时更新分数。当然,你会想找到一种更通用的方法来挑选赢家,而不是通过所有六个赢家组合来工作,但这是学生的练习。:-)

您需要执行
p1+=一些_分数
来实际更改
p1
。你不能只做p1+一些分数,因为它不会保存结果。
if game1 == game2:
    print ("Tie!")
elif game1 == "Rock" and game2 == "Scissors":
    print ("Player 1 wins!")
    p1 += 1
elif game1 == "Rock" and game2 == "Paper":
    print ("Player 2 wins!")
    p2 += 1

print ("Player 1's Score Currently Is...", p1)    
print ("Player 2's Score Currently Is...", p2)