Jan-05-2019, 02:03 PM
Hi everyone, I'm new to programming so sorry in advance if my mistake is a stupid one.
I am having trouble making my if-elif-else statement execute properly in my dice rolling simulator, it always defers to the statement for the else part, no matter the input. For example, if the user inputs 1 to play again, they will be told the input is not valid. Same thing if they input 2 in order to stop playing.
Here is my code:
I am having trouble making my if-elif-else statement execute properly in my dice rolling simulator, it always defers to the statement for the else part, no matter the input. For example, if the user inputs 1 to play again, they will be told the input is not valid. Same thing if they input 2 in order to stop playing.
Here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
from random import randint def diceRollingSimulator(): dice = randint( 1 , 6 ) print (dice) diceRollingSimulator() answer = input ( "Would you like to play again? (enter 1 for yes or 2 for no): " ) if answer = = 1 : diceRollingSimulator() elif answer = = 2 : print ( "Thanks for playing!" ) else : print ( "Not a valid input!" ) |