Posted By Naveen Singh on 10 Apr 2023
python-program
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
a = int(input("enter any number:"))
if a%2==0:
print("even number")
else:
print("odd number")
Output-:
enter any number= 4
even number
a = int(input("enter any number:"))
if a>0:
print("positive number")
else:
print("negative number")
Output-:
enter any number= 5
positive number
Y = int(input("Enter year:"))
if Y%4==0:
print("Leap year")
else:
print("Not a leap year")
Output-:
Enter year: 2020
Leap year
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
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
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
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
x = int(input(“Enter first point=”))
y = int(input(“Enter second point=”))
if (x>0 and y>0):
print(“points lies in first quadrant”)
elif (x>0 and y<0):
print(“points lies in second quadrant”)
elif (x<0 and y>0):
print(“points lies in third quadrant”)
elif (x<0 and y<0):
print(“points lies in fourth quadrant”)
else:
print(“points are in origin(0,0)”)
Output-:
Enter first point= 3
Enter second point= 5
points lies in first quadrant
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):
print(“candidate is eligible for admission”)
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
candidate is eligible for admission
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
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= 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
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
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
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
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
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
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
grade = input("Enter Grade="))
if(grade == 'E'):
print("Excellent")
elif(grade == 'V'):
print("Very Good")
elif(grade == 'G'):
print("Good")
elif(grade == 'A'):
print("Average")
elif(grade == 'F'):
print("Fail")
else:
print("enter valid grade")
Output-:
Enter Grade = A
Average
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
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
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
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
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):
radius = int(input(“Enter radius=”))
Area = 3.14 * radius * radius
print(“Area of circle=”, Area)
elif (fig_code == 2):
l = int(input(“Enter length=”))
b = int(input(“Enter breadth=”))
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
print(“ 1 -> Addition”)
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=”))
print(“Addition=”, a+b)
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
Addition= 8
I Hope आपको Python में if condition के program समझ में आए होगे। यदि आपको किसी program में कोई doubt है तो comment section में comment करके पूछ सकते हैं।