In [1]:
#https://www.programiz.com/python-programming/if-elif-else
In [3]:
"""
if expression:
statement(s)
else:
statement(s)
"""
Out[3]:
In [10]:
age=17
if(age>=18):
print("eligible")
print("welcome")
print("vlr training")
In [11]:
age=17
if(age>=18):
print("eligible")
else:
print("not eli")
In [12]:
"""
if test expression:
Body of if
elif test expression:
Body of elif
else:
Body of else"""
Out[12]:
In [13]:
# 1 12 child 13 19 teange 20 young
In [36]:
a=-1
if (a>=0 and a<=5):
print("small chaild")
elif (a>=5 and a<=12):#(t and f)
print("big chaild")
elif (a>=13 and a<=19):#(t and f)
print("teen")
else:
print("young")
In [37]:
# In this program, we input a number
# check if the number is positive or
# negative or zero and display
# an appropriate message
# This time we use nested if
In [41]:
num=0
if num >= 0: #t
if num==0:#f
print("Zero")
else:
print("Positive number")
else:
print("Negative number")
No comments:
Post a Comment