2017-04-25 53 views
-5
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 

在这个岩石纸剪刀游戏中,我找到了与我的分数变量麻烦。由于某种原因我编程的方式我的代码意味着我的分数不会加起来。请帮助:) 提前致谢基本变量不添加!!! (我的代码的一个部分)

+1

您需要执行'p1 + = some_score'来切换'p1'。你不能只是'p1 + some_score',因为它不会保存结果。 –

回答

1

如果是平局,则无需更新分数。但是:

if game1 != game2: 
    p1 = p1 + score # Replace score with a number or assign score a value 
    p2 = p2 + score 

目前比分没有被更新,因为这样做p1 + score不会更新p1的价值。你需要重新分配给它。因此,p1 = p1 + scorep1 += score

0

当我在IDLE上运行你的代码时,我会遇到各种问题。这且不说,如果你正在试图做的是增加一个变量,它的所有号码,那么你可以做

# 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 

这一切正在做的是加1到变量的当前数量。

应该那么简单。

0

你还没有添加任何东西的分数。首先,你处理分数的唯一陈述是表达式,而不是分配。你需要通过存储的结果早在变量保持的值,如

number = number + 1 

,您可以缩短

number += 1 

其次,你已经添加了0到P1和P2。即使您存储了结果,该值也不会改变。


REPAIR

您需要确定哪些玩家赢了,然后增加与玩家的分数。我不会为你写详细的代码,但考虑一下:

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) 

你看到那是怎样工作的吗?只有当玩家赢得一轮时才更新分数。当然,你会希望找到一个更为普遍的选择赢家的方式,而不是通过所有六个获胜组合,但这是对学生的练习。 :-)

相关问题