2017-04-10 6 views
0

私のコードは2ロール変数(Roll1とRoll2)があるところを再生しているようですが、Roll1とRoll2が表示されますが、プログラムを実行するとコードのこの部分が2-3回実行されます一度遊ぶ。私が間違って何をやっている、これは私があなたの問題はループのためのあなたが働いている方法であると考えているコードコードを再生していますか?

from random import randint 
print("Welcome") 
print("You are are playing a game of dice, this is a two player game, who ever rolls the highest number wins") 
name1 = input("What is Player 1's Name?") 
print("Hello", name1) 
name2 = input("What is Player 2's Name?") 
print("Greetings",name2) 
condition = "Start" 
while condition == "Start": 
    Dice = int(input("Please select number of dice you would like to use between 1 and 5")) 
    if (Dice >= 1 and Dice <= 5): 
     Sides = int(input("Please select number of sides on dice you would like to use")) 
    if (Sides >= 2 and Sides <= 5): 
    if (Dice >=0 and Sides >= 1): 
     condition = "start" 
    print("You have selected", Dice," dice and", Sides,"Sides") 
    condition = "play" 
    Roll1 = 0 
    Roll2 = 0 
    Player1 = 0 
    Player2 = 0 
while condition == "play": 
    for i in range(Dice): 
     Roll1 += randint(1,Sides) #The code here 
     Roll2 += randint(1,Sides) 
     print (name1,"'s Roll", Roll1) 
     print (name2,"'s Roll", Roll2) #To Here 
    if Roll1 > Roll2: 
     print (name1," wins") 
     Player1 += 1 
    elif Roll2 > Roll1: 
     print (name2," wins") 
     Player2 += 1 
    elif Roll1 == Roll2: 
     print ("It is a draw no points this round") 
    if(input("Press 'Enter' to play again or type 'reveal' to reveal the scores and quit") == "reveal"): 
     print ("The Score for",name1,"is",Player1,) 
     print ("The Score for",name2,"is",Player2,) 
     if(input("Press 'Enter' to goto the start or 'quit' to quit the game") =="quit"): 
      print ("Goodbye") 
      break 
    else: 
     condition == "Start" 

答えて

0

のコメントでマークされた学生とこれに非常に新しい、午前のpythonを使用しています。私はいくつかのコメントを追加しました。

for i in range(Dice): # this means you'll 'roll' Dice times. 
    Roll1 += randint(1,Sides) # This is fine. 
    Roll2 += randint(1,Sides) 
print (name1,"'s Roll", Roll1) # these statements need to be outside the loop 
print (name2,"'s Roll", Roll2) # because you only want to print once 

ロールをすべてのロールの累計にしたいとします。

関連する問題