Hello.
I am new to programing and Python. And I have created a simple program that randomize the output (it's a magic 8 ball) the program works fine. But now to My problem:
I created a loop so long as the user dosen't press "n" the program restarts, however Im trying to find a command so that only "j" restarts the program as of now all letters except n restarts the program. Here is the code:
import random
import console
val = ""
while val != "n":
console.clear()
def getAn(ansnu):
if ansnu == 1:
return "Du kommer bli rik inom närmaste framtiden"
elif ansnu == 2:
return "Du kommer få tur i kärleken"
elif ansnu == 3:
return "Du kommer att göra en resa"
elif ansnu == 4:
return "Du kommer att få framgång i ditt yrke"
elif ansnu == 5:
return "Den närmaste framtiden ser otydlig ut"
elif ansnu == 6:
return "Olycka väntar dig"
elif ansnu == 7:
return "Framtiden är mörk..."
elif ansnu == 8:
return "Hmmm ser inte bra"
# resten måste vara inanför while oxå
r = random.randint(1,8)
fort = getAn(r)
print(fort)
print("Vill du testa igen (j/n)")
val = input()
if val == "n":
print("hejdå")
console.hide_output()
As you can see there is the option to try again print("Vill du testa igen (j/n)")
val = input()
But any button execpt n restarts the program. How can I change it so only j restarts it???