1.
Simple Addition Program
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
sum = num1 + num2
print("Sum =", sum)
2. Even or Odd
number = int(input("Enter a number: "))
if number % 2 == 0:
print("Even Number")
else:
print("Odd Number")
3. Largest Number
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
largest = max(a, b, c)
print("Largest number is:", largest)
4. Temperature Converter
F=95C+32F = \frac{9}{5}C + 32F=59C+32
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (9/5 * celsius) + 32
print("Temperature in Fahrenheit:", fahrenheit)
5. Multiplication Table
number = int(input("Enter a number: "))
for i in range(1, 13):
print(number, "x", i, "=", number * i)
6. Area of a Circle
A=πr2A = \pi r^2A=πr2
rrr
3.0
A=πr2≈28.27A = \pi r^2 \approx 28.27A=πr2≈28.27
C=2πr≈18.85C = 2\pi r \approx 18.85C=2πr≈18.85
r = 3.00
import math
radius = float(input("Enter radius: "))
area = [Link] * radius ** 2
print("Area =", area)
7. Student Grade System
score = int(input("Enter student score: "))
if score >= 70:
print("Grade: A")
elif score >= 60:
print("Grade: B")
elif score >= 50:
print("Grade: C")
elif score >= 45:
print("Grade: D")
elif score >= 40:
print("Grade: E")
else:
print("Grade: F")
8. 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")
9. Login System
username = input("Enter username: ")
password = input("Enter password: ")
if username == "admin" and password == "1234":
print("Login Successful")
else:
print("Invalid Username or Password")
10. Sum of Numbers 1–100
total = 0
for i in range(1, 101):
total += i
print("Total sum =", total)
11. Factorial Program
number = int(input("Enter a number: "))
factorial = 1
for i in range(1, number + 1):
factorial *= i
print("Factorial =", factorial)
12. Count Vowels
word = input("Enter a word: ")
vowels = "aeiouAEIOU"
count = 0
for letter in word:
if letter in vowels:
count += 1
print("Number of vowels:", count)
13. Number Guessing Game
secret_number = 7
guess = int(input("Guess the number: "))
while guess != secret_number:
print("Wrong guess")
guess = int(input("Try again: "))
print("Correct!")
14. Store Student Names
students = ["Ali", "Amina", "John", "Fatima", "David"]
for student in students:
print(student)
15. Find Maximum in List
numbers = [10, 45, 23, 89, 12]
largest = max(numbers)
print("Largest number is:", largest)
16. Average Score
scores = [70, 85, 90, 60, 75]
average = sum(scores) / len(scores)
print("Average score =", average)
17. Attendance System
attendance = []
for i in range(3):
name = input("Enter student name: ")
[Link](name)
print("Students Present:")
for student in attendance:
print(student)
print("Total Present:", len(attendance))
18. Create a Function
def greet():
print("Welcome to Python Programming")
greet()
19. Calculator Functions
def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
return a / b
print(add(10, 5))
print(subtract(10, 5))
print(multiply(10, 5))
print(divide(10, 5))
20. BMI Calculator
BMI=weightheight2BMI = \frac{weight}{height^2}BMI=height2weight
weight = float(input("Enter weight in kg: "))
height = float(input("Enter height in meters: "))
bmi = weight / (height ** 2)
print("BMI =", bmi)
21. Save Student Record
file = open("[Link]", "w")
name = input("Enter student name: ")
[Link](name)
[Link]()
print("Record saved successfully")
22. Read From File
file = open("[Link]", "r")
content = [Link]()
print(content)
[Link]()
23. Simple CBT System
score = 0
answer1 = input("1. Python is a programming language? (yes/no): ")
if [Link]() == "yes":
score += 1
answer2 = input("2. 2 + 2 = 4? (yes/no): ")
if [Link]() == "yes":
score += 1
print("Your score is:", score)
24. Student Result Processing
scores = []
for i in range(5):
score = int(input("Enter score: "))
[Link](score)
total = sum(scores)
average = total / len(scores)
print("Total =", total)
print("Average =", average)
25. Simple ATM Simulation
balance = 1000
print("1. Deposit")
print("2. Withdraw")
print("3. Check Balance")
choice = int(input("Enter choice: "))
if choice == 1:
amount = float(input("Enter amount to deposit: "))
balance += amount
print("New Balance =", balance)
elif choice == 2:
amount = float(input("Enter amount to withdraw: "))
if amount <= balance:
balance -= amount
print("New Balance =", balance)
else:
print("Insufficient Balance")
elif choice == 3:
print("Balance =", balance)
else:
print("Invalid Choice")
26. Prime Number Checker
number = int(input("Enter a number: "))
is_prime = True
if number <= 1:
is_prime = False
else:
for i in range(2, number):
if number % i == 0:
is_prime = False
break
if is_prime:
print("Prime Number")
else:
print("Not a Prime Number")
27. Password Strength Checker
password = input("Enter password: ")
if len(password) >= 8:
print("Strong Password")
else:
print("Weak Password")
28. Random Password Generator
import random
import string
characters = string.ascii_letters + [Link]
password = ""
for i in range(8):
password += [Link](characters)
print("Generated Password:", password)
29. Login System with 3 Attempts
correct_password = "1234"
attempts = 3
while attempts > 0:
password = input("Enter password: ")
if password == correct_password:
print("Login Successful")
break
else:
attempts -= 1
print("Wrong password")
print("Attempts left:", attempts)
if attempts == 0:
print("Account Locked")
30. Mini Chatbot
message = input("You: ").lower()
if message == "hello":
print("Bot: Hello there!")
elif message == "hi":
print("Bot: Hi!")
elif message == "how are you":
print("Bot: I am fine")
else:
print("Bot: I don't understand")