Elif and else , python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

Elif and else , python

Hello when im writing a programm with the command else and elif for example when you writing if and then else the result are going to the end but if the command if them elif and then else the result isnt showing the result of the command elif but is showing the result of if and else , pls explain why??

2nd Aug 2020, 4:12 PM
Kir-Py
Kir-Py - avatar
23 Answers
+ 16
neee... jetzt atme mal durch wenn der code nicht tut, was er soll, ist er nicht korrekt. so einfach ist das. if zahl > 7: gib daddel aus elif zahl > 5: gib hoddel aus else: das ist der Lumpensammler, falls es nicht bisher gepasst hat. gib lumpen aus es gilt das highlander Prinzip: es kann nur eine Abzweigung geben. 8: daddel(aber nicht hoddel) 6: hoddel 3: lumpen okay? so... next level if zahl > 7: gib daddel aus if zahl > 5: gib hoddel aus else: der ist nur der else zum if >5 gib Lumpen aus 8: daddel hoddel 6: hoddel 3: lumpen wenn du enter eingegeben musst, dann ist da ein input() zuviel. So... nochmal durchatmen... debuggen will gelernt sein. 😉
2nd Aug 2020, 5:38 PM
Oma Falk
Oma Falk - avatar
+ 8
Hello Kir-Py Please show a code.
2nd Aug 2020, 4:12 PM
Denise Roßberg
Denise Roßberg - avatar
+ 6
Kir-Py Für dich auf deutsch: Deine Frage lässt sich im Moment nicht beantworten. Wir brauchen einen vollständigen Code mit der vollständigen Bedingung für a, b und c.
2nd Aug 2020, 5:13 PM
Denise Roßberg
Denise Roßberg - avatar
+ 5
Kir-Py It depends on what is assigned to the variables. I can't tell unless I see your full code.
2nd Aug 2020, 5:07 PM
Ore
Ore - avatar
+ 5
Okay. See this working example in that case https://code.sololearn.com/cyGHvSppbxR5/
2nd Aug 2020, 5:14 PM
Ore
Ore - avatar
+ 4
Kir-Py, this is no code, it's pseudo-code, and a rather unclear and incomplete one at that. As Denise Roßberg said, if you want help, you need to show us the actual code you're struggling with, otherwise we can't figure it out.
2nd Aug 2020, 4:40 PM
HonFu
HonFu - avatar
+ 3
Kir-Py elif is equal else: if: For example: if a: print("a") else: if b: print("b") #So the output is not coming as you expected.
2nd Aug 2020, 4:38 PM
Baratov Hojiakbar
Baratov Hojiakbar - avatar
+ 3
What are the conditions? (This is still no code, and incomplete.) Kannst es auch auf deutsch versuchen, wenn das hilft. 😉
2nd Aug 2020, 4:42 PM
HonFu
HonFu - avatar
+ 3
elif cannot come after the else It should be like this if a: print(a) elif c: print(c) else: print(b) Disclaimer: you may need to adjust the indentation
2nd Aug 2020, 5:04 PM
Ore
Ore - avatar
+ 2
....=input('...') If....'HI': Elif....'hello': Else: 'Good' The result must be for example Hi Pushing ENTER Hello Pushing ENTER Good But my result was for example Hi Pushing ENTER Good. Dont tell me if the code isnt correct cause its correct ..
2nd Aug 2020, 4:17 PM
Kir-Py
Kir-Py - avatar
+ 2
I mean Input (a,b,c) If a: Print a Else: Print b Elif c Print c
2nd Aug 2020, 4:41 PM
Kir-Py
Kir-Py - avatar
+ 2
The result must be a b c ?
2nd Aug 2020, 4:44 PM
Kir-Py
Kir-Py - avatar
+ 2
Ore then what is the result
2nd Aug 2020, 5:06 PM
Kir-Py
Kir-Py - avatar
+ 2
This code example wasnt a purpose for something just to know what the result could be
2nd Aug 2020, 5:11 PM
Kir-Py
Kir-Py - avatar
+ 2
Das ist nicht der Code , sondern einfach nur welches resultat mit schlüßel wörter if elif und else wäre
2nd Aug 2020, 5:15 PM
Kir-Py
Kir-Py - avatar
+ 2
Weil ich auf den Computer arbeite und ich will mit If Elif und Else so machen damit man nach dem Betrag von die Schlüßel Wörter z.b der Ergebnis (Von If:) ..... Dann muss man ENTER drücken damit es die Ergebnis von Elif zeigt u.s.w bis es zum Else kommt
2nd Aug 2020, 5:22 PM
Kir-Py
Kir-Py - avatar
+ 2
You have to gives us a code to see to your question
3rd Aug 2020, 10:22 AM
Oladetohun Oluwakorede Emmanuel
Oladetohun Oluwakorede Emmanuel - avatar
+ 2
Ore Bro, Your code is like , a,b,c = False , True , False if a: print(a) elif c: print(c) else: print(b) Then the answer will be b Because a , c are False , so the code will go to last.. At the thing you are saying that 'elif' cant be used after 'else' is correct !
3rd Aug 2020, 2:06 PM
__k_maaz__ [ INACTIVE ]
__k_maaz__ [ INACTIVE ] - avatar
+ 1
it`s depended about code
3rd Aug 2020, 12:32 PM
Fareed
Fareed - avatar
+ 1
a
3rd Aug 2020, 12:32 PM
Pratik Kinage
Pratik Kinage - avatar