I want to prompt the user to input how many times they want to roll a die, then generate a random number between 1 and 6. I then need to print what their number is and if it is even or odd.
The code I posted below is what I came up with for a single die roll that allows the user to roll every time they press enter, prints their number, and prints even or odd depending on their roll.
I have been trying to modify my single die roll code to allow for the user to input how many times they want to roll the die instead of hitting enter each time, but nothing I try seems to work. I've seen some people write functions for their dice games, maybe that would be a better route?
I just started teaching myself Python a few days ago, so over explanations are more than appreciated. Thanks for any help!
The Attempt at a Solution
# Single Dice Roll
repeat = True
Die = str(random.randint(1,6))
print("Your roll was a " + Die)
if Die == "1" or Die == "3" or Die == "5":
print("You rolled an odd number")
elif Die == "2" or Die == "4" or Die == "6":
print("You rolled an even number")
repeat = "Yes" in input()
7.5 KB Views: 4,699