Programs
Programs
Input:
num1 = int(input("Enter the first integer: "))
num2 = int(input("Enter the second integer: "))
if num1 == num2:
print("The two integers are equal.")
else:
print("The two integers are not equal.")
Output:
Enter the first integer: 15
Enter the second integer: 15
The two integers are equal.
2.
Input:
number = int(input("Enter an integer: "))
if number % 2 == 0:
print(f"The number {number} is even.")
else:
print(f"The number {number} is odd.")
Output:
Enter an integer: 15
The number 15 is odd.
3.
Input:
number = float(input("Enter a number: "))
if number > 0:
print(f"The number {number} is positive.")
elif number < 0:
print(f"The number {number} is negative.")
else:
print("The number is zero.")
Output:
Enter a number: 15
The number 15.0 is positive.
4.
Input:
year = int(input("Enter a year: "))
if (year % 4 == 0):
print(f"The year {year} is a leap year.")
else:
print(f"The year {year} is not a leap year.")
Output:
5.
Input:
age = int(input("Enter your age: "))
if age >= 18:
print("Congratulations! You are eligible for casting your vote.")
else:
print("Sorry, you are not eligible to cast your vote yet.")
Output:
Enter your age: 21
Congratulations! You are eligible for casting your vote.
6.
Input:
m = int(input("Enter the value of m: "))
if m > 0:
n=1
elif m == 0:
n=0
else:
n = -1
Output:
Enter the value of m: -5
The value of n is: -1
7.
Input:
height = int(input("Enter the height of the person in centimeters: "))
if height < 140:
answer = "Dwarf"
elif 140 <= height <= 170:
answer = "Average height"
else:
answer = "Tall"
Output:
Enter the height of the person in centimeters: 135
The person is Dwarf.
8.
Input:
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
num3 = int(input("Enter the third number: "))
Output:
Enter the first number: 15
Enter the second number: 25
Enter the third number: 52
The largest number is: 52
9.
Input:
x = int(input("Enter the X coordinate: "))
y = int(input("Enter the Y coordinate: "))
Output:
Enter the X coordinate: 7
Enter the Y coordinate: 9
The coordinate point (7, 9) lies Quadrant I.
10.
Input:
if maths >= 65 and physics >= 55 and chemistry >= 50 and (total_all >= 190 or total_maths_physics >=
140):
print("The candidate is eligible for admission.")
else:
print("The candidate is not eligible for admission.")
Output:
Input the marks obtained in Physics: 65
Input the marks obtained in Chemistry: 51
Input the marks obtained in Mathematics: 72
The candidate is not eligible for admission.
11.
Input:
a = float(input("Enter the coefficient a: "))
b = float(input("Enter the coefficient b: "))
c = float(input("Enter the coefficient c: "))
if discriminant > 0:
root1 = (-b + math.sqrt(discriminant)) / (2 * a)
root2 = (-b - math.sqrt(discriminant)) / (2 * a)
print(f"The roots are real and different: {root1} and {root2}")
elif discriminant == 0:
root = -b / (2 * a)
print(f"The roots are real and the same: {root}")
else:
print("The roots are imaginary; No solution.")
Output:
Enter the coefficient a: 1
Enter the coefficient b: 5
Enter the coefficient c: 7
The roots are imaginary; No solution.
12.
Input:
roll_no = input("Input the Roll Number of the student: ")
name = input("Input the Name of the Student: ")
physics = int(input("Marks obtained in physics:"))
chemistry = int(input("Marks obtained in chemistry:"))
computer = int(input("Marks obtained in computer:"))
total_marks = physics + chemistry + computer
percentage = (total_marks / 300) * 100
Output:
Input the Roll Number of the student: 784
Input the Name of the Student: james
Marks obtained in physics:70
Marks obtained in chemistry:80
Marks obtained in computer:90
Roll No : 784
Name of Student : james
Marks in Physics : 70
Marks in Chemistry : 80
Marks in Computer Application : 90
Total Marks = 240
Percentage = 80.0
Division = First
13.
Input:
temperature = float(input("Enter the temperature in centigrade: "))
if temperature < 0:
message = "Freezing weather"
elif 0 <= temperature < 10:
message = "Very Cold weather"
elif 10 <= temperature < 20:
message = "Cold weather"
elif 20 <= temperature < 30:
message = "Normal in Temp"
elif 30 <= temperature < 40:
message = "It's Hot"
else:
message = "It's Very Hot"
print(message)
Output:
14.
Input:
side1 = float(input("Enter the length of the first side: "))
side2 = float(input("Enter the length of the second side: "))
side3 = float(input("Enter the length of the third side: "))
Output:
if angle1 + angle2 + angle3 == 180 and angle1 > 0 and angle2 > 0 and angle3 > 0:
print("The triangle is valid.")
else:
print("The triangle is not valid.")
Output:
Enter the first angle: 40
Enter the second angle: 55
Enter the third angle: 65
The triangle is not valid.
16.
Input:
char = input("Enter a character: ")
if char.isalpha():
print("This is an alphabet.")
elif char.isdigit():
print("This is a digit.")
else:
print("This is a special character.")
Output:
Enter a character: @
This is a special character.
17.
Input:
char = input("Enter an alphabet: ").lower()
if char in 'aeiou':
print("The alphabet is a vowel.")
else: print("The alphabet is a consonant.")
Output:
Enter an alphabet: k
The alphabet is a consonant.
18.
Input:
cost_price = float(input("Enter the cost price: "))
selling_price = float(input("Enter the selling price: "))
if selling_price > cost_price:
profit = selling_price - cost_price
print(f"You can book your profit amount: {profit}")
elif selling_price < cost_price:
loss = cost_price - selling_price
print(f"You have incurred a loss amount: {loss}")
else:
print("There is no profit or loss.")
Output:
Enter the cost price: 500
Enter the selling price: 700
You can book your profit amount: 200.0
19.
Input:
customer_id = input("Enter the Customer ID: ")
customer_name = input("Enter the Customer Name: ")
units_consumed = float(input("Enter the units consumed: "))
20.
Input:
grade = input("Enter the grade: ").upper()
if grade == 'E':
remarks = "Excellent"
elif grade == 'V':
remarks = "Very Good"
elif grade == 'G':
remarks = "Good"
elif grade == 'A':
remarks = "Average"
elif grade == 'F':
remarks = "Fail"
else:
remarks = "Invalid grade entered"
print(f"Remarks: {remarks}")
Output:
Enter the grade: A
Remarks: Average
21.
Input:
if day_number == 1:
day_name = "Monday"
elif day_number == 2:
day_name = "Tuesday"
elif day_number == 3:
day_name = "Wednesday"
elif day_number == 4:
day_name = "Thursday"
elif day_number == 5:
day_name = "Friday"
elif day_number == 6:
day_name = "Saturday"
elif day_number == 7:
day_name = "Sunday"
else:
day_name = "Invalid day number"
Output:
Enter the day number (1 to 7): 4
The day is: Thursday
22.
Input:
digit = int(input("Enter a digit (0 to 9): "))
if digit == 0:
word = "Zero"
elif digit == 1:
word = "One"
elif digit == 2:
word = "Two"
elif digit == 3:
word = "Three"
elif digit == 4:
word = "Four"
elif digit == 5:
word = "Five"
elif digit == 6:
word = "Six"
elif digit == 7:
word = "Seven"
elif digit == 8:
word = "Eight"
elif digit == 9:
word = "Nine"
else:
word = "Invalid input"
Output:
Enter a digit (0 to 9): 4
The digit in word is: Four
23.
Input:
month_number = int(input("Enter the month number (1 to 12): "))
if month_number == 1:
month_name = "January"
elif month_number == 2:
month_name = "February"
elif month_number == 3:
month_name = "March"
elif month_number == 4:
month_name = "April"
elif month_number == 5:
month_name = "May"
elif month_number == 6:
month_name = "June"
elif month_number == 7:
month_name = "July"
elif month_number == 8:
month_name = "August"
elif month_number == 9:
month_name = "September"
elif month_number == 10:
month_name = "October"
elif month_number == 11:
month_name = "November"
elif month_number == 12:
month_name = "December"
else:
month_name = "Invalid month number"
Output:
Enter the month number (1 to 12): 4
The month is: April
24:
Input:
month_number = int(input("Enter the month number (1 to 12): "))
Output:
Enter the month number (1 to 12): 7
The month has 31 days.