You are on page 1of 3

11/29/22, 10:24 AM 17 Oct 2022 if else - Jupyter Notebook

# Decision Making COnditional


#if
#if-else
#elif
#nested if
#Colon is recqired. It seperates header of the compound statement from the body
#identation is recquired afterv the colon="4 spaces"

In [ ]:

In [ ]:

if condition:
statement

In [ ]:

if condition:
statement
else:
statement

In [ ]:

if condition:
statement
elif condition:
statement
else:
statement

In [4]:

a=4
b=6
if a<b:
print(a)

In [5]:

a=4
b=6
if a>b:
print(a)
else:
print(b)

localhost:8888/notebooks/17 Oct 2022 if else.ipynb 1/3


11/29/22, 10:24 AM 17 Oct 2022 if else - Jupyter Notebook

In [6]:

a=4
b=6
if a>b:
print(a)
elif a==b:
print(a,b)
else:
print(b)

In [15]:

a=input("enter")
b=4
c=5
if a=='q':
if b<c:
print(b+c)
else:
print(b-c)
else:
if(b<c):
print(b*c)
else:
print(b/c)

enter18

20

In [5]:

a=int(input("enter age"))
if a>=18:
x=input("Enter name:")
print("Dear", x, "you are Eligible to vote")
else:
print("Not Eligible to vote")

enter age56

Enter name:Thomas

Dear Thomas you are Eligible to vote

In [15]:

st="Python"
nlist=["pen", "Python", "pencil", "ink", "rubber"] #CREATION OF LIST
if st in nlist: #if in command
print(st+ "\ttutorial")

Python tutorial

localhost:8888/notebooks/17 Oct 2022 if else.ipynb 2/3


11/29/22, 10:24 AM 17 Oct 2022 if else - Jupyter Notebook

In [20]:

if int(input("enter a num\t"))==5:
print("Yes")

enter a num 5

Yes

In [23]:

x=200
y= (x==500)
z=not(x==500) #NOT
print(y)
print(x,y,z)

False

200 False True

In [24]:

n=2
print(n)
result=n+8 if n>4 else n/2 #if else in one line First the conditionis checked
print(result)

1.0

In [25]:

n=10
print(n)
result=n+8 if n>4 else n/2 #if else in one line
print(result)

10

18

In [ ]:

localhost:8888/notebooks/17 Oct 2022 if else.ipynb 3/3

You might also like