Python Programs
[Link] on voting eligibility-
age = int(input("Enter your age: "))
if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")
Example Output
Enter your age: 20
You are eligible to vote.
[Link] of finding factorial-
num = int(input("Enter a number: "))
fact = 1
if num < 0:
print("Factorial does not exist for negative numbers.")
# If number is 0
elif num == 0:
print("Factorial of 0 is 1")
# For positive numbers
else:
for i in range(1, num + 1):
fact = fact * i # multiplying numbers
print("Factorial of", num, "is", fact)
Example Output
Enter a number: 5
Factorial of 5 is 120
[Link] for identify even and odd number
num = int(input("Enter a number: "))
if num % 2 == 0:
print("The number is Even.")
else:
print("The number is Odd.")
Example Output
Enter a number: 8
The number is Even.
4. Program to check prime number
num = int(input("Enter a number: "))
count = 0 # To count number of factors
for i in range(1, num + 1):
if num % i == 0:
count += 1 # Increase count if divisible
if count == 2:
print("Prime Number")
else:
print("Not a Prime Number")
Example Output
Enter a number: 7
Prime Number
[Link] program for number table multiplication-
num = int(input("Enter a number: "))
# Loop from 1 to 10
for i in range(1, 11):
print(num, "x", i, "=", num * i)
Example Output
Enter a number: 5
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
...
5 x 10 = 50
6. Program for greatest among three numbers-
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
num3 = int(input("Enter third number: "))
# Checking conditions
if num1 >= num2 and num1 >= num3:
print("Greatest number is:", num1)
elif num2 >= num1 and num2 >= num3:
print("Greatest number is:", num2)
else:
print("Greatest number is:", num3)
Example Output
Enter first number: 10
Enter second number: 25
Enter third number: 15
Greatest number is: 25
7. Python Program for simple intrest-
principal = float(input("Enter Principal amount: "))
rate = float(input("Enter Rate of Interest: "))
time = float(input("Enter Time (in years): "))
# Formula for Simple Interest
si = (principal * rate * time) / 100
# Display result
print("Simple Interest is:", si)
Example Output
Enter Principal amount: 1000
Enter Rate of Interest: 5
Enter Time (in years): 2
Simple Interest is: 100.0
8. Program to Add Element using append()in a list
numbers = [10, 20, 30]
# Taking input from user
new_element = int(input("Enter element to add: "))
# Adding element to list
[Link](new_element)
print("Updated List:", numbers)
Example Output
Enter element to add: 40
Updated List: [10, 20, 30, 40]