I want to create an if-condition, but I'm not sure how to. - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: I want to create an if-condition, but I'm not sure how to. (/thread-28905.html) |
I want to create an if-condition, but I'm not sure how to. - LeqendFire - Aug-09-2020 I want to create an if-condition, but I'm not sure how to do it... I would like, that if the else-condition is true, it prints my message. How can I do that? That's my recent try: y = 'lol' if y == True: print ('y ist wahr!') elif y == False: print ('y ist nicht wahr!') else: print ('y ist weder wahr noch nicht wahr') if else == True: print ('Ich habe es, denke ich, verstanden')And that's the error I get: I'm a starter, so it's probably easy to solve for you professionals
RE: I want to create an if-condition, but I'm not sure how to. - Yoriz - Aug-09-2020 something = False else_true = False if something: print('something is True') else: print('something is False') else_true = True if else_true: print('else_true is True') RE: I want to create an if-condition, but I'm not sure how to. - ndc85430 - Aug-09-2020 It doesn't make sense for else to have a condition. Like in English, it means "in the other case". That's also why you can't have an else on its own.
RE: I want to create an if-condition, but I'm not sure how to. - LeqendFire - Aug-09-2020 (Aug-09-2020, 10:55 AM)ndc85430 Wrote: It doesn't make sense for What do you mean with "you can't have an else on its own"? Could you explain that please? RE: I want to create an if-condition, but I'm not sure how to. - ndc85430 - Aug-09-2020 As in, you can't write else: # something herebecause again, else means "in the other case", so it has to follow an if or elif .Of course, an if on its own makes sense. You might want to do something when the condition is True , but nothing if it is False .
RE: I want to create an if-condition, but I'm not sure how to. - LeqendFire - Aug-09-2020 (Aug-09-2020, 04:15 PM)ndc85430 Wrote: As in, you can't write Alright, got it |