This question is an exact duplicate of:
I asked this question before and thought I had a working solution, but as it turns out I did not. My question is how do I detect when a maximum integer is selected by random.randint().
import random
import webbrowser
def easteregg():
print("ROLLLLLLL")
url = 'https://youtu.be/dQw4w9WgXcQ?t=41s'
webbrowser.open(url)
def inphandle(choice):
if choice==4:
roll = random.randint(1,4)
elif choice==6:
roll = random.randint(1,6)
elif choice==8:
roll = random.randint(1,8)
elif choice==10:
roll = random.randint(1,10)
elif choice==20:
roll = random.randint(1,20)
elif choice!=[4,6,8,10,20]:
print("Sorry you must choose one of the set options.")
main()
return roll
def dice(roll):
if roll==1:
print("Min roll! Try again!")
print(roll)
elif roll == 4 and roll == random.randint(1,4):
print("Max roll! Great roll!")
print(roll)
elif roll == 6 and roll == random.randint(1,6):
print("Max roll! Great roll!")
print(roll)
elif roll == 8 and roll == random.randint(1,8):
print("Max roll! Great roll!")
print(roll)
elif roll == 10 and roll == random.randint(1,10):
print("Max roll! Great roll!")
print(roll)
elif roll == 20 and roll == random.randint(1,20):
print("Max roll! Great roll!")
print(roll)
elif roll!=max or roll!=1:
print("Good roll!")
print(roll)
#Main menu with either exit which of course exits or roll option which will redirect back to main().
def mainmenu():
print("Please choose from the following options:")
print("Roll | EXIT")
option = str(input())
if option=="EXIT" or option=="exit" or option=="Exit":
print("Goodbye!")
exit
if option=="roll" or "ROLL" or "Roll":
main()
def main():
print("Options: 4-Sided|6-Sided|8-Sided|10-Sided|20-Sided")
choice = int(input("Please enter a number corresponding to the number of
faces on your dice. E.x. 4 for 4-Sided: "))
cont = input("Would you like to roll the dice? Y or N: ")
while cont=="y" or cont=="Y":
roll = inphandle(choice)
dice(roll)
cont = input("Would you like to roll again? Y or N: ")
while cont=="n" or cont=="N":
easteregg()
mainmenu()
main()
You can see where I attempted to use elif in inphandle(), but my variable cannot be both a number and randint(). I tried to use max but this did not work and I do not know if there is a way for me to use this and my teacher did not have an answer to how I could use it either.
Aucun commentaire:
Enregistrer un commentaire