So, I am finally getting down on this piece of work, but I can't seem to stop it from asking for user input. Basically, what I want the code to do, is get a number from the user, and if it has a match, then go ahead and print out each "roll # (number) was (number)." If the first input does not have a match, then it may ask again (up to three times till a match is made). If a match is made, the user wins, if not, the computer wins. I think range(3) might be my issue but I am just not sure, as I did try removing it.
dashes = 65
dashes_count = 65 * "-"
print(f'You have three rolls of the dice to match a number you select.')
print(f'Good Luck!')
print(dashes_count)
import random
die = 0
roll = 0
def dice_roll():
dieroll = random.randint(1, 6) + random.randint(1, 6)
return dieroll
for die in range(3):
die1 = int(input(f'Choose a number between 2 and 12: '))
die2 = int(input(f'Choose a number between 2 and 12: '))
die3 = int(input(f'Choose a number between 2 and 12: '))
roll1 = dice_roll()
roll2 = dice_roll()
roll3 = dice_roll()
if die1 == roll1:
break
print(f'Roll # 1 was {roll1}')
print(f'Roll # 2 was {roll2}')
print(f'Roll # 3 was {roll3}')
print(f'You Win! - Thanks for playing!')
if die2 == roll2:
break
print(f'Roll # 1 was {roll1}')
print(f'Roll # 2 was {roll2}')
print(f'Roll # 3 was {roll3}')
print(f'You Win! - Thanks for playing!')
if die3 == roll3:
break
print(f'Roll # 1 was {roll1}')
print(f'Roll # 2 was {roll2}')
print(f'Roll # 3 was {roll3}')
print(f'You Win! - Thanks for playing!')
else:
print(f'Roll # 1 was {roll1}')
print(f'Roll # 2 was {roll2}')
print(f'Roll # 3 was {roll3}')
print(f'You Lose! - Thanks for playing!')
I am looking for an output that works like this:
Choose a number between 2 and 12: 3 # user input
roll # 1 was 5
roll # 2 was 3 # the matching number
roll # 3 was 11
You Win! - Thanks for playing!
# where the user input matches 1 or all rolls and prints all roll results.
# otherwise
Choose a number between 2 and 12: g # not valid / not a match
Choose a number between 2 and 12: 5 # the second try
roll # 1 was 7
roll # 2 was 12
roll # 3 was 5 # the matching number
You Win! - Thanks for playing
# " Choose a number between 2 and 12: " is limited to 3 tries only
# if all three tries receive in valid / unmatches numbers, print "You lose!"