0% found this document useful (0 votes)
5 views8 pages

Python Programs Project File

The document contains a series of Python programs demonstrating various functionalities such as arithmetic operations, finding the greatest of three numbers, checking if a number is positive, negative, or zero, and determining if a number is a palindrome. Additional programs include displaying a multiplication table, calculating percentage and pass/fail status based on marks, checking if a number is even or odd, sorting a list, displaying the day of the week based on a number, and converting seconds into hours, minutes, and seconds. Each program includes user input and prints the corresponding output.

Uploaded by

a68838576
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)
5 views8 pages

Python Programs Project File

The document contains a series of Python programs demonstrating various functionalities such as arithmetic operations, finding the greatest of three numbers, checking if a number is positive, negative, or zero, and determining if a number is a palindrome. Additional programs include displaying a multiplication table, calculating percentage and pass/fail status based on marks, checking if a number is even or odd, sorting a list, displaying the day of the week based on a number, and converting seconds into hours, minutes, and seconds. Each program includes user input and prints the corresponding output.

Uploaded by

a68838576
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 FOR PROJECT FILE

1# Python program to perform all arithmetic operations on two numbers


# Input two numbers
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

# Arithmetic operations
print("Addition =", a + b)
print("Subtraction =", a - b)
print("Multiplication =", a * b)
print("Division =", a / b)
print("Modulus =", a % b)
print("Floor Division =", a // b)
print("Exponentiation =", a ** b)
Enter first number: 8
Enter second number: 3
Addition = 11
Subtraction = 5
Multiplication = 24
Division = 2.6666666666666665
Modulus = 2
Floor Division = 2
Exponentiation = 512
2# Python program to find the greatest of three numbers

# Input three numbers


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
# Check greatest number
if a >= b and a >= c:
print("Greatest number is:", a)
elif b >= a and b >= c:
print("Greatest number is:", b)
else:
print("Greatest number is:", c)
Enter first number: 25
Enter second number: 40
Enter third number: 30
Greatest number is: 40
3# Python program to check whether a number is positive, negative or zero

# Input number
num = int(input("Enter a number: "))

# Check the number


if num > 0:
print("The number is Positive")
elif num < 0:
print("The number is Negative")
else:
print("The number is Zero")
Enter a number: -7
The number is Negative
4# Python program to check whether a number is a palindrome

# Input number
num = int(input("Enter a number: "))

# Store original number


original = num
reverse = 0
# Reverse the number
while num > 0:
digit = num % 10
reverse = reverse * 10 + digit
num = num // 10

# Check palindrome
if original == reverse:
print("The number is a Palindrome")
else:
print("The number is Not a Palindrome")
Enter a number: 121
The number is a Palindrome
Enter a number: 123
The number is Not a Palindrome
5# Python program to display the table of a number
# Input number
num = int(input("Enter a number: "))

# Display table
print("Table of", num)
for i in range(1, 11):
print(num, "x", i, "=", num * i)
Enter a number: 7
Table of 7
7x1=7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70
6 # Python program to calculate percentage and check pass or fail

# Input marks of five subjects


m1 = float(input("Enter marks of Subject 1: "))
m2 = float(input("Enter marks of Subject 2: "))
m3 = float(input("Enter marks of Subject 3: "))
m4 = float(input("Enter marks of Subject 4: "))
m5 = float(input("Enter marks of Subject 5: "))

# Calculate total and percentage


total = m1 + m2 + m3 + m4 + m5
percentage = (total / 500) * 100 # assuming each subject is out of 100

# Display percentage
print("Percentage =", percentage, "%")

# Check pass or fail


if percentage < 33:
print("Result: Fail")
else:
print("Result: Pass")
Enter marks of Subject 1: 60
Enter marks of Subject 2: 55
Enter marks of Subject 3: 70
Enter marks of Subject 4: 65
Enter marks of Subject 5: 50
Percentage = 60.0 %
Result: Pass
7# Python program to check whether a number is even or odd

# Input number
num = int(input("Enter a number: "))

# Check even or odd


if num % 2 == 0:
print("The number is Even")
else:
print("The number is Odd")
Enter a number: 14
The number is Even
# Python program to display items of a list

# Create a list
my_list = [10, 20, 30, 40, 50]

# Display list items


print("Items of the list are:")
for item in my_list:
print(item)
Items of the list are:
10
20
30
40
50

8 # Python program to arrange list items in ascending or descending order

# Input list from user


items = []
n = int(input("Enter number of elements in the list: "))

for i in range(n):
[Link](int(input("Enter element: ")))

# User choice
choice = input("Enter A for Ascending or D for Descending: ")

# Sorting according to choice


if choice == 'A' or choice == 'a':
[Link]()
print("List in Ascending Order:", items)
elif choice == 'D' or choice == 'd':
[Link](reverse=True)
print("List in Descending Order:", items)
else:
print("Invalid choice")
Enter number of elements in the list: 5
Enter element: 4
Enter element: 1
Enter element: 3
Enter element: 5
Enter element: 2
Enter A for Ascending or D for Descending: A
List in Ascending Order: [1, 2, 3, 4, 5]

9 # Python program to display day name according to week number

# Input week number


day = int(input("Enter a number (1-7): "))

# Check and display day name


if day == 1:
print("Sunday")
elif day == 2:
print("Monday")
elif day == 3:
print("Tuesday")
elif day == 4:
print("Wednesday")
elif day == 5:
print("Thursday")
elif day == 6:
print("Friday")
elif day == 7:
print("Saturday")
else:
print("Invalid input! Please enter a number between 1 and 7.")
Enter a number (1-7): 3
Tuesday
10 # Python program to convert seconds into hours, minutes and seconds

# Input seconds
seconds = int(input("Enter time in seconds: "))

# Calculate hours, minutes and remaining seconds


hours = seconds // 3600
minutes = (seconds % 3600) // 60
remaining_seconds = seconds % 60

# Display result
print("Hours:", hours)
print("Minutes:", minutes)
print("Seconds:", remaining_seconds)
Enter time in seconds: 3665
Hours: 1
Minutes: 1
Seconds: 5

You might also like