#๐Ÿ”’ Else shows up when i use insert if,

45 messages ยท Page 1 of 1 (latest)

plucky forum
#

In my script i have 2 If commands and attempted to use an else command to see if i could make is say something special if i wrote anything else, if i didnt write in what was in the "If area" im quite new to python

torpid masonBOT
#

@plucky forum

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

plucky forum
#

heres what i mean

limber meteor
plucky forum
#

Sorry to ask but what is elif? and whats its purpose

limber meteor
#

only when the if statement is false it jumps to elif condition

#

@plucky forum run this ```py
a=int(input("enter: "))
b=int(input("enter: "))
c=int(input("enter: "))

if a<b:
print(" a lesser")
elif b<c:
print("b lesser")
else:
print("ok")

#

and replace elif with if and see the difference

plucky forum
#

Oh okay i'll try it out Thanks

lilac spoke
#

Each if/elif/else block is made ofpy if condition: 'Exactly one if.' elif some_other_condition: 'Zero or more elifs.' else: 'Zero or one else.'In that order. The first condition to be satisfied is the only clause to have its indented section run.

#

Once you deindent with something that isn't an elif or an else, you're terminating the current if/elif/else block.

#

So another if starts another if/elif/else.

limber meteor
#

u forgor print function

lilac spoke
#

I didn't.

limber meteor
#

but ur code is better

#

@lilac spoke ayo can we use even 3 elif in same block

lilac spoke
#

Yes.

limber meteor
#

tf cool

#

let me try

lilac spoke
#

!e py if 'some condition': ... ... elif 'some other condition': ...

limber meteor
#

yea it worked I never thought of this

torpid masonBOT
lilac spoke
#

Note here how I deindent with something that isn't an elif.

#

or an else

limber meteor
#

cool

lilac spoke
#

At the second ... we're still syntactically valid.

#

But then we hit the elif.

#

Which at this point is an elif without an if.

limber meteor
#

it is like if else if?

lilac spoke
#

elif stands for else if.

#

i.e. If none of the above conditions are satisfied, but this condition is...

limber meteor
#

hmm

lilac spoke
#

Then else, if used, coming last, if none of the above conditions are satisfied, do this.

limber meteor
#

@lilac spoke since how many years u are learning python

lilac spoke
#

Approximately eight to nine years.

limber meteor
#

alr cya I need to earn way more things

lilac spoke
#

Just take it a step at a time.

limber meteor
lilac spoke
#

Avoid burnout.

limber meteor
#

I just learn mini things daily

lilac spoke
#

Good.

torpid masonBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.