# if condition program in python - Bharosewale

Posted By Naveen Singh on 10 Apr 2023

python-program ## 1) Write a python program to accept two integers and check whether they are equal or not.

a = int(input(“Enter first number:”))

b = int(input(“Enter second number:”))

if a==b:

print(“Both numbers are equal”)

else:

print(“numbers are not equal”)

Output-:

Enter first number: 5

Enter second number: 6

## 2) Write a python program to check whether a given number is even or odd

a = int(input("enter any number:"))

if a%2==0:

print("even number")

else:

print("odd number")

Output-:

enter any number= 4

even number

## 3) Write a python program to check whether a given number is positive or negative

a = int(input("enter any number:"))

if a>0:

print("positive number")

else:

print("negative number")

Output-:

enter any number= 5

positive number

## 4) Write a python program to check whether a given year is a leap year or not

Y = int(input("Enter year:"))

if Y%4==0:

print("Leap year")

else:

print("Not a leap year")

Output-:

Enter year: 2020

Leap year

## 5) Write a python program to read the age of a candidate and determine whether it is eligible for casting his/her own vote.

age = int(input("Enter age:"))

if age>=18:

print("Eligible for casting vote")

else:

print("Not eligible for voting")

Output-:

Enter age: 25

Eligible of casting vote

## when m is 0 and -1 when m is less than 0

m=int(input("Enter value of m:"))

if m>0:

n=1

print("value of n is:",n)

elif m==0:

n=0

print("value of n is:",n)

else:

n=-1

print("value of n is:",n)

Output-:

Enter value of m: 5

value of n is:1

## 7) Write a python program to accept the height of a person in centimetre and categorize the person according to their height.

height = int(input(“Enter height of a person=”))

If (height<=135):

print(“person is dwarf”)

elif (height>=135 and height<155):

print(“person is in average”)

elif (height>155):

print(“person is tall”)

else:

print(“invalid entry”)

Output-:

Enter height of a person= 150

person is in average

## 8) Write a python program to find the largest of three numbers.

a = int(input(“Enter first number=”))

b = int(input(“Enter second number=”))

c = int(input(“Enter third number=”))

if (a>b and a>c):

print(“ first number is greater”)

elif (b>a and b>c):

print(“second number is greater”)

elif (c>a and c>b):

print(“third number is greater”)

else:

print(“all numbers are equal”)

Output-:

Enter first number= 24

Enter second number=43

Enter third number=34

second number is greater

## 9) Write a python program to accept a coordinate point in a XY coordinate system and determine in which quadrant the coordinate point lies.

x = int(input(“Enter first point=”))

y = int(input(“Enter second point=”))

if (x>0 and y>0):

elif (x>0 and y<0):

elif (x<0 and y>0):

elif (x<0 and y<0):

else:

print(“points are in origin(0,0)”)

Output-:

Enter first point= 3

Enter second point= 5

## 10) Write a python program to find the eligibility of admission for a professional course based on the following criteria

Phy = int(input(“ Enter marks obtained in physics=”))

Chem = int(input(“ Enter marks obtained in chemistry=”))

Math = int(input(“ Enter marks obtained in maths=”))

total  = Phy+Chem

sum  = Phy+Chem+Math

print(“Total in math and physics=”,total)

print(“Total in math,physics and chemistry=”,sum)

if (Math>=65 and Phy>=55 and Chem>=50 and Total>=190 and Sum>=140):

else:

print(“candidate is not eligible for admission”)

Output-:

Enter marks obtained in physics=  65

Enter marks obtained in chemistry= 51

Enter marks obtained in maths= 75

Total in math and physics= 140

Total in math,physics and chemistry= 191

## 11) Write a python program to calculate the root of a Quadratic Equation.

a = int(input(“Enter first value=”))

b = int(input(“Enter second value=”))

c = int(input(“Enter third value=”))

D = (b**2)– (4*a*c)

if (D>0):

print(“roots are real and unequal”)

elif (D==0):

print(“roots are real and equal”)

else:

print(“roots are imaginary”)

Output-:

Enter first value= 1

Enter first value= 5

Enter first value= 7

roots are imaginary

## 12) Write a C program to read roll no, name and marks of three subjects and calculate the total, percentage and division.

roll_no = int(input(“Enter roll no of a student=”))

name = input(“Enter name of a student=”)

phy = int(input(“Enter first marks=”))

chem = int(input(“Enter second marks=”))

math = int(input(“Enter third marks=”))

total = phy+chem+math

per = total/3

if (per>=85):

print(“First Division”)

elif(per>=65 and per<85):

print(“Second Division”)

elif (per>=30 and per<65):

print(“third Division”)

else:

print(“fail”)

## Temp >=40 then Its Very Hot

Temp= int(input(“Enter temperature=”))

if (temp<0):

print(“Freezing weather”)

elif (temp>=0 and temp<10):

print(“very cold weather”)

elif (temp>=10 and temp<20):

print(“cold weather”)

elif (temp>=20 and temp<30):

print(“normal weather”)

elif (temp>=30 and temp<40):

print(“hot weather”)

elif (temp>=40):

print(“very hot weather”)

else:

print(“invalid temperature”)

Output-:

Enter temperature= 40

very hot

## 14) Write a C program to check whether a triangle is Equilateral, Isosceles or Scalene.

a = int(input(“Enter first side=”))

b = int(input(“Enter second side=”))

c = int(input(“Enter third side=”))

if( a==b and a==c and b==c):

print(“angle is an equilateral triangle”)

elif( a==b and a==c):

print(“angle is an isosceles triangle”)

else:

print(“angle is an scalene triangle”)

Output-:

Enter first side= 20

Enter second side= 20

Enter third side= 28

angle is an isosceles triangle

## 15) Write a C program to check whether a triangle can be formed by the given value for the angles

a = int(input(“Enter first side=”))

b = int(input(“Enter second side=”))

c = int(input(“Enter third side=”))

total = a+b+c

if(total==180):

print(“valid triangle”)

else:

print(“invalid triangle”)

Output-:

Enter first side= 60

Enter second side= 40

Enter third side= 20

Invalid triangle

## 16) Write a python program to check whether a character is an alphabet, digit or special character

char = input("Enter any character=")

if(char>='a' and char<='z') or (char>='A' and char<='Z'):

print("alphabet")

elif(char>='0' and char<='9'):

print("digit")

else:

print("special character")

Output-:

Enter any character= &

special character

## 17) Write a python program to check whether an alphabet is a vowel or not

alphabet = input("Enter alphabet=")

if(alphabet=='a' or alphabet=='e' or alphabet=='i' or alphabet=='o' or alphabet=='u' or alphabet=='A' or alphabet=='E' or alphabet=='I' or alphabet=='O' or

alphabet=='U'):

print("alphabet is a vowel")

else:

print("alphabet is not a vowel")

Output-:

Enter alphabet= f

alphabet is not a vowel

## 18) Write a python program to calculate profit and loss on a transaction

sp = int(input("Enter selling price="))

cp = int(input("Enter cost price="))

if(sp>cp):

print("Profit")

elif(cp>sp):

print("Loss")

else:

print(" no profit no loss")

Output-:

Enter selling price= 200

Enter cost price= 100

Profit

## If bill exceeds Rs400 than a surcharge of 15% will be charged and the minimum bill should be of Rs100/-

Cust_id = int(input("Enter customer ID="))

Cust_name = input("Enter customer name=")

unit = float(input("Enter unit consumed="))

if(unit<=199):

charge = unit*1.20

elif(unit>200 and unit<400):

charge = unit*1.20 + (unit-199)*1.50

elif(unit>400 and unit<600):

charge = unit*1.20 +unit*1.50+ (unit-199)*1.80
else:
charge = unit*1.20+unit*1.50+ unit*1.80 +(unit-199)*2.00

if(charge>400):

surcharge = charge*0.15

total = charge + surcharge

elif(charge<100):

total = 100

else:

total = charge

print("Customer ID=", Cust_id)

print("Customer name=", Cust_name)

print("unit consumed by the customer=", unit)

print("Surcharge=", surcharge)

print("Total Bill=", total)

Output-:

Enter customer ID= 101

Enter customer name= harrison

Enter unit consumed= 800

Customer ID= 101

Customer name= harrison

unit consumed by the customer= 800

Surcharge= 240.0

Total Bill= 1840.00

## E->Excellent, V->Very Good, G-> Good, A->Average, F->Fail

print("Excellent")

print("Very Good")

print("Good")

print("Average")

print("Fail")

else:

Output-:

Average

## 21) Write a python program to read any day number and display the day name

day_no = int(input(" Enter day number="))

if(day_no == 1):

print("Sunday")

elif(day_no == 2):

print("Monday")

elif(day_no == 3):

print("Tuesday")

elif(day_no == 4):

print("Wednesday")

elif(day_no == 5):

print("Thursday")

elif(day_no == 6):

print("Friday")

elif(day_no == 7):

print("Saturday")

else:

print("enter valid day number")

Output-:

Enter day number= 6

Friday

## 22) Write a python program to read any digit and display in the word

digit = int(input("Enter any digit="))

if(digit == 1):

print("ONE")

elif(digit == 2):

print("TWO")

elif(digit == 3):

print("THREE")

elif(digit == 4):

print("FOUR")

elif(digit == 5):

print("FIVE")

elif(digit == 6):

print("SIX")

elif(digit == 7):

print("SEVEN")

elif(digit == 8):

print("EIGHT")

elif(digit == 9):

print("NINE")

Output-:

Enter any digit = 5

FIVE

## 23) Write a python program to read any month number in integer and display month name in the word

month_no = int(input("Enter month number="))

if(month_no == 1):

print("JANUARY")

elif(month_no == 2):

print("FEBRUARY")

elif(month_no == 3):

print("MARCH")

elif(month_no == 4):

print("APRIL")

elif(month_no == 5):

print("MAY")

elif(month_no == 6):

print("JUNE")

elif(month_no == 7):

print("JULY")

elif(month_no == 8):

print("AUGUST")

elif(month_no == 9):

print("SEPTEMBER")

elif(month_no == 10):

print("OCTOBER")

elif(month_no == 11):

print("NOVEMBER")

elif(month_no == 12):

print("DECEMBER")

Output-:

Enter month number= 5

MAY

## 24) Write a python program to read any month number and display the number of days in the month

month_no = int(input(" Enter month number="))

if(month_no == 1):

print("31 days in  this month")

elif(month_no == 2):

print("28 days in this month")

elif(month_no == 3):

print("30 days in this month")

elif(month_no == 4):

print("31 days in this month")

elif(month_no == 5):

print("30 days in this month")

elif(month_no == 6):

print("31 days in this month")

elif(month_no == 7):

print("30 days in this month")

elif(month_no == 8):

print("31 days in this month")

elif(month_no == 9):

print("30 days in this month")

elif(month_no == 10):

print("31 days in this month")

elif(month_no == 11):

print("30 days in this month")

elif(month_no == 12):

print("31 days in this month")

Output-:

Enter month number = 5

30 days in this month

## 25) Write a python program which is a menu driven program to compute the area of a various geometrical shapes

print(“ 1 -> Area of Circle”)

print(“ 2 -> Area of Rectangle”)

print(“ 3 -> Area of Triangle”)

print(“ 4 -> Area of Square”)

fig_code = int(input(“Enter figure code=”))

if (fig_code == 1):

print(“Area of circle=”, Area)

elif (fig_code == 2):

l = int(input(“Enter length=”))

Area = l * b

print(“Area of rectangle=”, Area)

elif ( fig_code == 3):

base = int(input(“Enter base=”))

height = int(input(“Enter height=”))

Area = 0.5 * base * height

print(“Area of triangle=”, Area)

elif (fig_code == 4):

side = int(input(“Enter side=”))

Area = side * side

print(“Area of square=”, Area)

else:

print("Invalid figure code")

Output-:

Enter figure code= 4

Enter side of square= 6

Area of square= 36

## 26. Write a python program which is a Menu-Driven Program to perform a simple calculation

print(“ 2 -> Subtraction”)

print(“ 3 -> Multiplication”)

print(“ 4 -> Division”)

fig_code = int(input(“Enter figure code=”))

if (fig_code == 1):

a = int(input(“Enter  first number=”))

b = int(input(“Enter second number=”))

elif (fig_code == 2):

a = int(input(“Enter  first number=”))

b = int(input(“Enter second number=”))

print(“Subtraction=”, a-b)

elif ( fig_code == 3):

a = int(input(“Enter  first number=”))

b = int(input(“Enter second number=”))

print(“Multiplicaion=”, a*b)

elif (fig_code == 4):

a = int(input(“Enter  first number=”))

b = int(input(“Enter second number=”))

print(“Division=”, a/b)

else:

print("invalid figure code")

Output-:

Enter figure code= 1

Enter first number= 4

Enter second number= 4