2017-04-25 65 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) 

你看到那是怎樣工作的嗎?只有當玩家贏得一輪時才更新分數。當然,你會希望找到一個更爲普遍的選擇贏家的方式,而不是通過所有六個獲勝組合,但這是對學生的練習。 :-)

相關問題