hi
when I try to add an else condition, i have the message "(variable) else: Any"
what is the problem please?
if reponse == 'Oui' or reponse == 'oui':
print("Super,le tirage va commencer" '!')
tirage()
else:
quitter = input("Souhaitez-vous quitter le jeux du loto (o/n) ? ")
Indentation defines code blocks in Python. Because "tirage()" is indented the same as "if response..." it marks the start of a new code block and it's execution is not affected by the if statement. You should be getting a syntax error because the "else:" does not have a corresponding "if". When I ran you code I get this message.
Output:
File "...\junk.py", line 4
else:
^
SyntaxError: invalid syntax
You will have a syntax error because tirage()
is not intended into the if
statement also your indents should be 4 spaces.
So does it mean that I cant use such a code or does it means I have to ident tirage()?
Because I tried to indent tirage() in the if block but it doenst works....
As we don't know what
tirage()
does and what does 'doesn't work' mean it's very hard to provide any assistance.
But one thing you could consider writing differently:
if response.lower() == 'oui': # covers all possible letter combinations: 'OUI', 'Oui', 'oUi' etc.