You are on page 1of 2

if <condition>:

<operation>
elif<condition>:
<operation>
.....
else:
<operation>

operators = > ,< ,>= , <=, ==, !=

a= int(input("enter a="))
if a%2 == 0:
print(a,"is even")
else:
print(a,"is odd")

a= int(input("enter a ="))
b= int(input("enter b="))
if a>b:
print(a,"is greater")
elif b>a:
print(b,"is greater")

else:
print("both are equal")

a = int(input("enter the value a ="))


b= int(input("enter the b ="))
o = input("enter the + - * / ")
if o == "+":
print(a+b)
elif o=="-":
print(a-b)
elif o=="*":
print(a*b)
elif o=="/":
print(a/b)
else:
print("invalid operators")

logical operators (and/or)


a= int(input("enter the a="))

if (a%2 == 0) and (a>20):

print("the value is even and greater than 20")

else:

print("error")

enter the a=40


the value is even and greater than 20

# nested if
if <condition>:
if <condition>:
<operation>
else:
<operation>

else:
<operation>

a= int(input("enter the a="))

if (a%2 == 0):

if a>20:

print("the value is even and greater than 20")

else:

print("the value is even but not greater than 20")

else:

print("error")

enter the a=6


the value is even but not greater than 20

You might also like