Professional Documents
Culture Documents
17 Oct 2022 If Else
17 Oct 2022 If Else
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)
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
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
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
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 [ ]: