Program 1: Menu-driven Calculator
print("***** SIMPLE CALCULATOR *****")
print("This program can perform:")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("------------------------------")
choice = int(input("Enter your choice (1-4): "))
if choice == 1 or choice == 2 or choice == 3 or choice == 4:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if choice == 1:
result = num1 + num2
print("You chose ADDITION.")
print("Result =", result)
elif choice == 2:
result = num1 - num2
print("You chose SUBTRACTION.")
print("Result =", result)
elif choice == 3:
result = num1 * num2
print("You chose MULTIPLICATION.")
print("Result =", result)
elif choice == 4:
if num2 != 0:
result = num1 / num2
print("You chose DIVISION.")
print("Result =", result)
else:
print("Error: Division by zero is not allowed.")
else:
print("Invalid choice. Please run the program again and choose
Program 2: Student Marksheet with Grade
print("******** STUDENT MARKSHEET ********")
name = input("Enter student name: ")
roll = input("Enter roll number: ")
print("-----------------------------------")
print("Enter marks out of 100 in 5 subjects.")
m1 = float(input("Marks in Subject 1: "))
m2 = float(input("Marks in Subject 2: "))
m3 = float(input("Marks in Subject 3: "))
m4 = float(input("Marks in Subject 4: "))
m5 = float(input("Marks in Subject 5: "))
total = m1 + m2 + m3 + m4 + m5
percentage = total / 5
if percentage >= 90:
grade = "A+"
elif percentage >= 80:
grade = "A"
elif percentage >= 70:
grade = "B+"
elif percentage >= 60:
grade = "B"
elif percentage >= 50:
grade = "C"
elif percentage >= 40:
grade = "D"
else:
grade = "E (Fail)"
print("
******** RESULT ********")
print("Name :", name)
print("Roll No. :", roll)
print("Total Marks:", total, "/ 500")
print("Percentage :", percentage, "%")
print("Grade :", grade)
if grade == "E (Fail)":
print("Status : FAIL. Work harder next time.")
else:
print("Status : PASS. Keep it up!")
Program 3: Number Properties Analyser
print("***** NUMBER ANALYSER *****")
n = int(input("Enter an integer: "))
if n > 0:
print("The number is POSITIVE.")
elif n < 0:
print("The number is NEGATIVE.")
else:
print("The number is ZERO.")
if n % 2 == 0:
print("The number is EVEN.")
else:
print("The number is ODD.")
temp = abs(n)
digit_sum = 0
digit_count = 0
while temp > 0:
digit = temp % 10
digit_sum = digit_sum + digit
digit_count = digit_count + 1
temp = temp // 10
print("Number of digits:", digit_count)
print("Sum of digits :", digit_sum)
Program 4: Reverse Number and
Palindrome Check
print("***** REVERSE AND PALINDROME CHECK *****")
n = int(input("Enter a number: "))
original = n
reverse_num = 0
while n > 0:
digit = n % 10
reverse_num = reverse_num * 10 + digit
n = n // 10
print("Original number:", original)
print("Reversed number:", reverse_num)
if original == reverse_num:
print("Result: The number is a PALINDROME.")
else:
print("Result: The number is NOT a palindrome.")
Program 5: Factorial and Sum of Factorials
print("***** FACTORIAL AND SERIES *****")
n = int(input("Enter a positive integer n: "))
if n < 0:
print("Factorial is not defined for negative numbers.")
else:
fact = 1
i = 1
while i <= n:
fact = fact * i
i = i + 1
print("Factorial of", n, "is", fact)
sum_of_factorials = 0
k = 1
while k <= n:
f = 1
j = 1
while j <= k:
f = f * j
j = j + 1
sum_of_factorials = sum_of_factorials + f
k = k + 1
print("Sum of factorials from 1! to", str(n) + "!", "is", sum_o
Program 6: Fibonacci Series with Sum
print("***** FIBONACCI SERIES *****")
terms = int(input("Enter number of terms (>=1): "))
if terms <= 0:
print("Number of terms must be positive.")
else:
a = 0
b = 1
count = 1
series_sum = 0
print("Fibonacci Series:")
while count <= terms:
print(a, end=" ")
series_sum = series_sum + a
c = a + b
a = b
b = c
count = count + 1
print("
Sum of first", terms, "Fibonacci numbers is", series_sum)
Program 7: List Operations (Search, Max,
Min, Average)
print("***** LIST OPERATIONS *****")
n = int(input("How many numbers do you want to enter? "))
numbers = []
i = 1
while i <= n:
value = float(input("Enter value " + str(i) + ": "))
[Link](value)
i = i + 1
print("
You entered the list:", numbers)
if len(numbers) > 0:
maximum = numbers[0]
minimum = numbers[0]
total = 0
for x in numbers:
if x > maximum:
maximum = x
if x < minimum:
minimum = x
total = total + x
average = total / len(numbers)
print("Maximum value:", maximum)
print("Minimum value:", minimum)
print("Sum of values:", total)
print("Average value:", average)
key = float(input("
Enter a number to search in the list: "))
found = False
for x in numbers:
if x == key:
found = True
break
if found:
print("The number", key, "is present in the list.")
else:
print("The number", key, "is NOT present in the list.")
else:
print("No numbers entered.")
Program 8: String Analysis (Vowels,
Consonants, Reverse)
print("***** STRING ANALYSER *****")
text = input("Enter a line of text: ")
length = len(text)
vowels = "aeiouAEIOU"
vowel_count = 0
consonant_count = 0
space_count = 0
other_count = 0
for ch in text:
if ch in vowels:
vowel_count = vowel_count + 1
elif ch == " ":
space_count = space_count + 1
elif [Link]():
consonant_count = consonant_count + 1
else:
other_count = other_count + 1
print("
Original text:", text)
print("Length of text :", length)
print("Number of vowels :", vowel_count)
print("Number of consonants :", consonant_count)
print("Number of spaces :", space_count)
print("Number of other symbols :", other_count)
reversed_text = ""
for ch in text:
reversed_text = ch + reversed_text
print("Reversed text:", reversed_text)
Program 9: Pattern Printing (Triangle and
Square)
print("***** PATTERN PRINTING *****")
rows = int(input("Enter number of rows for triangle: "))
print("
Right-angled triangle of stars:")
i = 1
while i <= rows:
j = 1
while j <= i:
print("*", end=" ")
j = j + 1
print()
i = i + 1
n = int(input("
Enter size of square: "))
print("
Square pattern of stars:")
row = 1
while row <= n:
col = 1
while col <= n:
print("*", end=" ")
col = col + 1
print()
row = row + 1
Program 10: Simple ATM Menu (Balance,
Deposit, Withdraw)
print("***** SIMPLE ATM MENU *****")
balance = 1000.0
print("Initial balance is:", balance)
while True:
print("
------- MENU -------")
print("1. Check balance")
print("2. Deposit money")
print("3. Withdraw money")
print("4. Exit")
print("--------------------")
choice = int(input("Enter your choice (1-4): "))
if choice == 1:
print("Your current balance is:", balance)
elif choice == 2:
amount = float(input("Enter amount to deposit: "))
if amount > 0:
balance = balance + amount
print("Amount deposited successfully.")
print("Updated balance:", balance)
else:
print("Deposit amount must be positive.")
elif choice == 3:
amount = float(input("Enter amount to withdraw: "))
if amount <= 0:
print("Withdrawal amount must be positive.")
elif amount > balance:
print("Insufficient balance. Transaction cancelled.")
else:
balance = balance - amount
print("Amount withdrawn successfully.")
print("Updated balance:", balance)
elif choice == 4:
print("Thank you for using this simple ATM program.")
break
else:
print("Invalid choice. Please select between 1 and 4.")