0% found this document useful (0 votes)
10 views14 pages

Python Programs Final

The document contains a series of Python programs that demonstrate various programming concepts, including calculating areas and perimeters, using arithmetic and relational operators, calculating discounts and simple interest, and managing student marks. It also includes programs for checking odd/even numbers, positive/negative numbers, and eligibility for voting, as well as creating patterns and managing student information. Each program is accompanied by sample code and output examples.

Uploaded by

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

Python Programs Final

The document contains a series of Python programs that demonstrate various programming concepts, including calculating areas and perimeters, using arithmetic and relational operators, calculating discounts and simple interest, and managing student marks. It also includes programs for checking odd/even numbers, positive/negative numbers, and eligibility for voting, as well as creating patterns and managing student information. Each program is accompanied by sample code and output examples.

Uploaded by

varunsushanth02
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python programs

[Link] a python program to find the area and perimeter of


a rectangle and triangle
CODE:-
l=int(input("enter the length of the rectangle"))
b=int(input("enter the breadth of the rectangle"))
area=l*b
p=2*(l+b)
print("the area is",area)
print("the perimeter is",p)
base = float(input("Enter the base of the triangle: "))
height = float(input("Enter the height of the triangle: "))
areat = 0.5 * base * height
print("The area of the triangle is:",areat)

Output:
enter the length of the rectangle 5
enter the breadth of the rectangle 4
the area is 20
the perimeter is 18
Enter the base of the triangle: 12
Enter the height of the triangle: 15
The area of the triangle is: 90.0

[Link] a Python Program to check all the arithmetic


operators in python
CODE:-
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("The sum is =", a + b)
print("The difference is =", a - b)
print("The product is =", a * b)
print("The quotient is =", a / b)
print("The integer quotient is =", a // b)
print("The remainder of division is =", a % b)
print("The power is =", a ** b)

Output:
Enter first number: 12
Enter second number: 5
The sum is = 17
The difference is = 7
The product is = 60
The quotient is = 2.4
The integer quotient is = 2
The remainder of division is = 2
The power is = 248832

3. Write a python program to check all relational


operators
CODE:-
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("a == b:", a == b)
print("a != b:", a != b)
print("a > b:", a > b)
print("a < b:", a < b)
print("a >= b:", a >= b)
print("a <= b:", a <= b)

Output:
Enter first number: 24
Enter second number: 34
a == b: False
a != b: True
a > b: False
a < b: True
a >= b: False
a <= b: True

4. Write a python program to calculate the discounted


amount and final price from original price and the
discount percentage.
CODE:-
op = float(input("Enter the original price: "))
dp= float(input("Enter the discount percentage: "))
da = (op * dp) / 100
fp = op - da
print("Original Price:",op)
print("Discount Percentage:",dp,"%")
print("Discount Amount: ",da)
print("Final Price after Discount:", fp)
Output:

Enter the original price: 15000


Enter the discount percentage: 20
Original Price: 15000.0
Discount Percentage: 20.0 %
Discount Amount: 3000.0
Final Price after Discount: 12000.0

5. Write a python program to calculate the Simple


Interest
CODE:-
principal = float( input("Enter the principal amount: "))
rate = float(input("Enter the annual interest rate (in
percentage): "))
time = float(input("Enter the time (in years): "))
interest = (principal * rate * time) / 100
print("The simple interest is: “,interest)

Output:

Enter the principal amount: 50000


Enter the annual interest rate (in percentage): 12
Enter the time (in years): 2
The simple interest is: 12000.0

[Link] a python to accept the marks scored by a


student in 5 subjects and calculate the percentage of
the student
CODE:-

subject1 = float(input("Enter marks for subject 1: "))


subject2 = float(input("Enter marks for subject 2: "))
subject3 = float(input("Enter marks for subject 3: "))
subject4 = float(input("Enter marks for subject 4: "))
subject5 = float(input("Enter marks for subject 5: "))
tm = subject1 + subject2 + subject3 + subject4 + subject5
max = 500
percentage = (tm / max) * 100
print("Total marks obtained:",tm," out of ",max)
print("Percentage obtained is:",percentage)

OUTPUT:-

[Link] a Python Program to Check if a Number is Odd or


Even.
CODE:-
num = int(input("Enter a number: "))
if (num % 2) == 0:
print("Number is Even number")
else:
print("Number is Odd number")
Output:
Enter a number: 2
Number is Even number

8. Write a Python Program to check if a Number is Positive,


Negative or Zero
CODE:-
a=int(input(“enter the number”))
if a > 0:
print("Number given by you is Positive")
elif a < 0:
print("Number given by you is Negative")
else:
print("Number given by you is zero")
Output:
enter the number -3
Number given by you is Negative

9. Write a python program to check the eligibility to cast a


vote
CODE:-
age=int(input(“enter your age”))
if(age>=18):
print(“yes you are eligible to cast a vote”)
else:
print(“sorry you are not eligible”)
Output:
enter your age 23
yes you are eligible to cast a vote

[Link] a Python program to input the billing amount and


age of a person. If the billing amount exceeds 10,000 and the
person is a senior citizen, a 15% discount will be applied. If
the billing amount exceeds 10,000 and the person is not a
senior citizen, a 10% discount will be applied. Otherwise, no
discount will be given.
CODE:-
ba=float(input("Enter the billing amount: "))
age=int(input("Enter the age of the person: "))
if ba>10000:
if age>=60:
​ discount=0.15*ba
else:
​ discount=0.10*ba
else:
discount=0
final_amount=ba-discount
print("Your Billing amount is =",ba)
print("Your discount amount is =",discount)
print("Total amount to be paid after discount is =",final_amount)

Output:
Enter the billing amount: 20000
Enter the age of the person: 79
Your Billing amount is = 20000.0
Your discount amount is = 3000.0
Total amount to be paid after discount is = 17000.0
[Link] Even Numbers from 1 to 20
CODE:-
for i in range(2, 21, 2):
print(i)

range(2, 21, 2) starts from 2 and increases by 2 each


time — so only even numbers are printed.
Output:

2
4
6
8
10
12
14
16
18
20

[Link] the Multiplication Table of a Number


CODE:-
num = int(input("Enter a number: "))
for i in range(1, 11):
print(num, "x", i, "=", num * i)
The loop runs 10 times to display the table for any number
entered by the user.
Output:
Enter a number: 5

5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50

[Link] the Factorial of a Number


CODE:-
num = int(input("Enter a number: "))
fact = 1
for i in range(1, num + 1):
fact =fact*i
print("Factorial of", num, "is", fact)

Output:
Enter a number: 7
Factorial of 7 is 5040
[Link] number pattern
for i in range(1, 6):
for j in range(1, i + 1):
print(j, end=" ")
print()

15. Number pyramid


for i in range(1, 6):
print(" " * (5 - i), end="")
for j in range(1, i + 1):
print(j, end=" ")
print()
Output:

[Link] a Python program that:Starts with an empty [Link]


add three students’ marks using append().Displays the list of
[Link] and prints the highest, lowest, total, and average
marks using built-in list functions.

marks = [ ]
m1 = int(input("Enter marks of first student: "))
m2 = int(input("Enter marks of second student: "))
m3 = int(input("Enter marks of third student: "))
[Link](m1)
[Link](m2)
[Link](m3)
print("Marks List:", marks)
if len(marks) > 0:
print("Highest Marks:", max(marks))
print("Lowest Marks:", min(marks))
print("Total Marks:", sum(marks))
print("Average Marks:", sum(marks) / len(marks))
else:
print("No marks available.")
17. Student Marks Management System
marks = []
while True:
print("Student Marks Menu \n")
print("1. Add Marks")
print("2. Remove Marks")
print("3. Display All Marks")
print("4. Show Highest, Lowest, and Average")
print("5. Sort Marks")
print("6. Exit")
choice = int(input("Enter your choice: "))
if choice == 1:
m = int(input("Enter marks to add: "))
[Link](m)
print("Marks added!")
elif choice == 2:
m = int(input("Enter marks to remove: "))
if m in marks:
[Link](m)
print("Marks removed!")
else:
print("Marks not found.")
elif choice == 3:
print("All marks:", marks)
elif choice == 4:
if len(marks) > 0:
print("Highest mark:", max(marks))
print("Lowest mark:", min(marks))
print("Average mark:", sum(marks)/len(marks))
else:
print("No marks available.")
elif choice == 5:
[Link]()
print("Sorted marks:", marks)
elif choice == 6:
print("Goodbye!")
break
else:
print("Invalid choice!")

With while True, the menu keeps looping — giving the user
continuous control until they explicitly choose to exit by
selecting option 6, which triggers break.
For descending order, just use the reverse=True
[Link](reverse=True)
18. Student management(student search)
students = [ ]
while True:
print("Student Management Menu")
print("1. Add Student")
print("2. Remove Student")
print("3. Display All Students")
print("4. Show First, Last, and Total Students")
print("5. Sort Students")
print("6. Search Student")
print("7. Exit")
choice = int(input("Enter your choice: "))
if choice == 1:
name = input("Enter student name to add: ")
[Link](name)
print("Student added!")
elif choice == 2:
name = input("Enter student name to remove: ")
if name in students:
[Link](name)
print("Student removed!")
else:
print("Student not found.")
elif choice == 3:
print("All students:", students)
elif choice == 4:
if len(students) > 0:
print("First student:", students[0]) # to find the
first student
print("Last student:", students[-1]) # to find the
last student
print("Total students:", len(students))
else:
print("No students available.")
elif choice == 5:
[Link]()
print("Sorted students:", students)
elif choice == 6:
name = input("Enter student name to search: ")
if name in students: # to search the student name
print( "Student found:", name)
else:
print("Student not found.")
elif choice == 7:
print("Goodbye!")
break
else:
print("Invalid choice!")

You might also like