I have a code that rolls two dice, for each players where they type 'roll' to roll each of their dice. However, if they don't type in 'roll' correctly, the code doesn't work properly and instead of asking the user over and over again to enter 'roll' again/ correctly, it goes through the code regardless without validating their input.
The code is supposed to ask Player 1 to roll their first then second dice for Round 1, then move onto Player 2's two dice for round one, then round 2, until both player have gone through 5 rounds, and if they type it incorrectly, it just asks for the right input until it's right.
import random
tot1 = 0
tot2 = 0
tot2 = 0
rnd2 = 0
for i in range (1,6):
while True:
from random import randint
print()
print("Player 1")
ro1_1 = input("Type 'roll' to roll your 1st dice: ")
if ro1_1 == 'roll':
dice1_1 = (randint(1,6))
print("Player1 dice 1:", dice1_1)
else:
ro1_1 = input("Type 'roll' to roll your 1st dice: ")
ro1_2 = input("Type 'roll' to roll your 2nd dice: ")
if ro1_2 == "roll":
dice1_2 = (randint(1,6))
print("Player1 Dice 2:", dice1_2)
else:
ro1_2 = input("Type 'roll' to roll your 1st dice: ")
print()
print ("Player1's total for round",(rnd1)," is:",tot1)
print()
print ("Player 2")
ro2_1 = input("Type 'roll' to roll your 1st dice: ")
if ro2_1 == 'roll':
dice2_1 = (randint(1,6))
print("Player2 Dice 1:", dice2_1)
else:
ro1_1 = input("Type 'roll' to roll your 1st dice: ")
ro2_2 = input("Type 'roll' to roll your 2nd dice: ")
if ro2_2 == 'roll':
dice2_2 = (randint(1,6))
print("Player2 Dice 2:", dice2_2)
else:
ro2_2 = input("Type 'roll' to roll your 1st dice: ")
break
print()
print ("Player2's total for round",(rnd2)," is:",tot2)
print()
break