Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help on else condition
#1
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) ? ")
Reply
#2
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
Reply
#3
You will have a syntax error because tirage() is not intended into the if statement also your indents should be 4 spaces.
Reply
#4
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....
Reply
#5
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.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#6
(May-18-2021, 06:31 AM)perfringo Wrote: 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.

thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  else condition not called when if condition is false Sandz1286 10 5,859 Jun-05-2020, 05:01 PM
Last Post: ebolisa
  [HELP] Nested conditional? double condition followed by another condition. penahuse 25 7,925 Jun-01-2020, 06:00 PM
Last Post: penahuse

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020