Skip to main content

15.Python If Else

PYTHON IF ELSE
    If else is the loop statement where if the condition is true or satisfied,the set of statements are executed.Else,other statements are executed.Almost every loops and functions in python relies on indentation which is used to define scope in the code. In short,python uses indentation instead of curly braces. It is also possible to have if statements inside if statements, this is called nested if statements. 
Elif : is a keyword which will be executed the if the previous if conditions were not true . 
Else: The else keyword catches anything which isn't caught by the preceding conditions. else can also be used without the elif. 

Program
n=56 
if n%2==0: 
    print(n,"is even") 
if 12<n<25: 
    print(n,"is between 12 to 25") 
elif 26<n<40: 
    print(n,"is between 26 to 40") 
elif n>40: 
    print(n,"is greater than 40") 
else: 
    print(n,"is odd") 
Output
56 is even 
56 is greater than 40 
If you have only one statement to execute, you can put it on the same line as the if statement.This technique is known as Ternary Operators, or Conditional Expressions.it is also possible to have multiple else statements on the same line using And,Or. 
Pass:if statements cannot be empty, the pass statement is used to avoid getting an error. 
Program
n=57 
if n%2==0:
    print(n,"is even") 
elif n%2!=0 :
    print(n,"is odd") 
else: 
    pass 
Output
57 is odd 
Check out the video below to learn python in detail!
Happy Learning!!

Comments

Popular posts from this blog

Get Ethical Hacking Project #1

Thanks for your interest in our course This is a paid course, 150 rs for Indian people, 5$ for international people Instructions to get course: Indian people can get the course by paying using this UPI id   tamilhacks@ybl  (KARTHIKEYAN T) send 150 Rs to this upi id with subject bug bounty and after payment take a screenshot and send that to email id tamilhackstech@gmail.com - you will get the course within 24 hours. (there will be no tax, when paying using upi id)     The above mentioned method is most preferable. if you don't have a upi id app, install  phonepe  or  google pay   app and register there and pay easily  or  pay here using the alternate method to get this course, this link cost 18% gst for the course . (nearly 30-100 Rs for tax and other charges here )   After payment you will receive a payment confirmation mail along with a downlink for the course, you can download the course file using that . the course is in zip format, so after downloading the file extra

Learn c++ in Tamil | Complete guide and tutorial | Beginner to Advance all concepts explained.

hi guys welcome , all the coding used in video are available here : /* hi guys welcome to learn c++ in tamil what is C++ how what software your own program schools,clg,institute.... start 1.interest 2.patience 3.fun 4.practise computer program - app - programming source code - hardware - fb running , executing machine language :  101010 assembly lang : mov h1; high lang : c , c++....java , js , python  eg :  a+b .....1001010  compiler :  human to machine              machine to human  rules :  a+b;  usage:  games, manufacturing , embedded , finance , graphics , etc...  Guide: 1.problem 2.solution - alternative 3.program  - C++ 4.compile  - turboc , ide , codeblocks , cmd 5.result   - library file - linker : #include<iostream.h>    input , output std::cout<<"welcome";   standard character out << " "; primary section : 1.statements   ;  end 2.functions   main() 3.syntax  , syntax error pra

Get Bug Bounty Course

Thanks for your interest in our course Limited Offer This is a paid course, Rs 10000 ,Rs 1000  for Indian people, 75$ 15$ for international people , 50$ 10$ for Srilankan people Instructions to get course: Indian people can get the course by paying using this UPI id  tamilhacks@ybl  send 1000 Rs to this upi id with subject bug bounty and after payment take a screenshot and send that to email id tamilhackstech@gmail.com - you will get the course within 24 hours. (there will be no tax, when paying using upi id)    The above mentioned method is most preferable. if you don't have a upi id app, install phonepe or google pay   app and register there and pay easily  or  pay here using the alternate method to get this course, this link cost 18% gst for the course . (nearly 30-100Rs for tax and other charges here ) After payment you will receive a payment confirmation mail along with a downlink for the course, you can download the course file using that. As for international peopl