- #1
jdawg
- 367
- 2
Homework Statement
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!
Homework Equations
The Attempt at a Solution
[/B]
import randomrepeat = Truewhile repeat:
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")
print("Roll again?")
repeat = "Yes" in input()