0
我的代碼似乎在重放一個點,其中有兩個滾動變量(Roll1和Roll2),然後打印Roll1和Roll2,但是當我運行該程序時,它運行這部分代碼2-3次,我只希望它玩一次。我在做什麼錯了,這是使用python我是一名學生,很新,上面標有註釋代碼代碼重播?
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"