0% found this document useful (0 votes)
17 views12 pages

Programs

Uploaded by

sadeemahmad.2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views12 pages

Programs

Uploaded by

sadeemahmad.2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

1.

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:

Enter a year: 2024


The year 2024 is a leap year.

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

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

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"

print(f"The person is {answer}.")

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: "))

if num1 >= num2 and num1 >= num3:


largest = num1
elif num2 >= num1 and num2 >= num3:
largest = num2
else:
largest = num3

print("The largest number is:", largest)

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: "))

if x > 0 and y > 0:


quadrant = "Quadrant I"
elif x < 0 and y > 0:
quadrant = "Quadrant II"
elif x < 0 and y < 0:
quadrant = "Quadrant III"
else:
quadrant = "Quadrant IV"

print(f"The coordinate point ({x}, {y}) lies {quadrant}.")

Output:
Enter the X coordinate: 7
Enter the Y coordinate: 9
The coordinate point (7, 9) lies Quadrant I.

10.
Input:

physics = int(input("Input the marks obtained in Physics: "))


chemistry = int(input("Input the marks obtained in Chemistry: "))
maths = int(input("Input the marks obtained in Mathematics: "))

total_all = physics + chemistry + maths


total_maths_physics = maths + physics

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: "))

discriminant = b**2 - 4*a*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

if percentage >= 60:


division = "First"
elif 50 <= percentage < 60:
division = "Second"
elif 40 <= percentage < 50:
division = "Third"
else:
division = "Fail"

print("Roll No :", roll_no)


print("Name of Student :", name)
print("Marks in Physics :", physics)
print("Marks in Chemistry :", chemistry)
print("Marks in Computer Application :", computer)
print("Total Marks =", total_marks)
print("Percentage =", percentage)
print("Division =", division)

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:

Enter the temperature in centigrade: 42


It's Very Hot

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: "))

if side1 == side2 == side3:


triangle_type = "Equilateral triangle"
elif side1 == side2 or side2 == side3 or side1 == side3:
triangle_type = "Isosceles triangle"
else:
triangle_type = "Scalene triangle"

print("This is a", triangle_type)

Output:

Enter the length of the first side: 50


Enter the length of the second side: 50
Enter the length of the third side: 60
This is a Isosceles triangle
15.
Input:
angle1 = float(input("Enter the first angle: "))
angle2 = float(input("Enter the second angle: "))
angle3 = float(input("Enter the third angle: "))

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: "))

if units_consumed <= 199:


charge_per_unit = 1.20
elif 200 <= units_consumed < 400:
charge_per_unit = 1.50
elif 400 <= units_consumed < 600:
charge_per_unit = 1.80
else:
charge_per_unit = 2.00

basic_amount = units_consumed * charge_per_unit

if basic_amount > 400:


surcharge = 0.15 * basic_amount
else:
surcharge = 0

total_amount = basic_amount + surcharge


if total_amount < 100:
total_amount = 100

print("Customer IDNO:", customer_id)


print("Customer Name:", customer_name)
print("Units Consumed:", units_consumed)
print(f"Amount Charges @Rs. {charge_per_unit:.2f} per unit : {basic_amount:.2f}")
print(f"Surcharge Amount : {surcharge:.2f}")
print(f"Net Amount Paid By the Customer : {total_amount:.2f}")
Output:
Enter the Customer ID: 1001
Enter the Customer Name: James
Enter the units consumed: 800

Customer IDNO: 1001


Customer Name: James
Units Consumed: 800.0
Amount Charges @Rs. 2.00 per unit : 1600.00
Surcharge Amount : 240.00
Net Amount Paid By the Customer : 1840.00

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:

day_number = int(input("Enter the day number (1 to 7): "))

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"

print(f"The day is: {day_name}")

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"

print(f"The digit in word is: {word}")

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"

print(f"The month is: {month_name}")

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): "))

if month_number == 1 or month_number == 3 or month_number == 5 or month_number == 7 or


month_number == 8 or month_number == 10 or month_number == 12:
days = 31
elif month_number == 2:
days = 28

elif month_number == 4 or month_number == 6 or month_number == 9 or month_number == 11:


days = 30
else:
days = "Invalid month number"

print(f"The month has {days} days.")

Output:
Enter the month number (1 to 12): 7
The month has 31 days.

You might also like