I'm sorry for the confusing title but I didn't really know what to put there. I'm a beginner at Python and I have run into a little problem. I put together a simple dice roller with the question if you want to play again or not. This works fine but I would like the program to ask the input again if answer by anything other than "y" or "n". For now I have this:
import random
print("Welcome to the dice game")
while True:
n = random.randint(1, 6)
print("Press Enter to roll the dice...")
input()
print(n)
answer = input("Do you want to play again? y/n: ")
if answer == "y":
continue
elif answer == "n":
break
else:
while answer != "n" or "y":
answer = input("Please input y or n: ")
print("Thanks for playing")
I'm guessing that I can't rename a variable that is outside a loop from the inside. Is it possible to return the code to the first input?
Thanks