0% found this document useful (0 votes)
3 views

Code

This document is a Python program that presents a menu-driven interface for various mini-programs, including palindrome checking, BMI calculation, and string manipulation. Users can select options to perform specific tasks or exit the program. The program runs in a loop until the user chooses to exit.

Uploaded by

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

Code

This document is a Python program that presents a menu-driven interface for various mini-programs, including palindrome checking, BMI calculation, and string manipulation. Users can select options to perform specific tasks or exit the program. The program runs in a loop until the user chooses to exit.

Uploaded by

mswastik145
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

import math

import random

print("Welcome to the wonderful world of Python!")


print("This menu-driven program allows you to choose a lot of mini-
programs.")
print("Simply enter the number corresponding to the program you wish to
run.")
print("To exit, select the exit option from the menu.")
print("Let's get started!\n")

while True:

print("Menu:")
print("1. Palindrome number checker")
print("2. Second largest number among group of entered numbers")
print("3. BMI and nutritional status calculator")
print("4. Check if square root of number is prime")
print("5. Sum of series: X + X^2/2 + X^3/3 +....X^n/n")
print("6. Armstrong number checker")
print("7. Alternatively capitalize each letter of a word")
print("8. Reverse a string")
print("9. Capitalize first letter of each word of a sentence")
print("10. Print the following pattern")
print("A")
print("BB")
print("CCC")
print("DDDD")
print("11. Exit")

choice = input("Enter your choice (1-11): ")

if choice == '1':

#Palindrome Number Checker

num = int(input("Enter the number: "))


temp = num
rem = rev = 0
while num > 0:
rem = num % 10
rev = rev * 10 + rem
num //= 10
if temp == rev:
print("Entered number is a palindrome.")

else:
print("Entered number is not a palindrome")

elif choice == '2':

#Second Largest number

l = sl = 0
while True:
n = int(input("Enter a number [0 to exit]: "))
if n == 0:
break

elif n > l:
sl = l
l = n

elif n > sl:


sl = n

if sl == 0:
print("Not enough valid numbers were entered.")

else:
print("Second largest number is", sl)

elif choice == '3':

#BMI and Nutrional Status

weight = int(input("Enter weight in kilograms: "))


height = float(input("Enter height in metre: "))
bmi = weight / height**2

print("Your BMI is: ",bmi)

if bmi <= 18.5:


print("BMI Category: Underweight")

elif 18.5 < bmi < 25:


print("BMI Category: Normal Weight")
elif 25 <= bmi < 30:
print("BMI Category: Overweight")

elif 30 <= bmi:


print("BMI Category: Obesity")

else:
print("Invalid input.")

elif choice == '4':

#Check if square root of a number is prime or not

n = int(input("Enter a number: "))


ctr = 0
sr = int(math.sqrt(n))

for i in range(1,sr+1):
if sr%i == 0:
ctr += 1

if ctr == 2:
print("Square root of entered number is prime")

else:
print("Square root of entered number is not a prime")

elif choice == '5':

#Sum of series x + x^2/2 + x^3/3 + ... + x^n/n

x = int(input("Enter the value of x: "))


n = int(input("Enter the value of n: "))
sum = 0

for i in range(1, n + 1) :
term = x ** i / i
sum += term

print("Sum =", sum)

elif choice == '6':


#Armstrong Number checker

num = int(input("Enter the number: "))


temp = num
rem = sum_d = 0
while num > 0:
rem = num % 10
sum_d+=rem*rem*rem
num //= 10

if temp == sum_d:
print("Entered number is an Armstrong number.")

else:
print("Entered number is not an Armstrong number.")

elif choice == '7':

#Alternatively capitalize every other letter


str=input("Your string: ")
length=len(str)
print("Original string: ",str)
str2=''
for a in range(0,length,2):
str2+=str[a]
if a<(length-1):
str2+=str[a+1].upper()
print("Alternatively capitalized string:",str2)

elif choice == '8':

#Reversed string

str = input("Enter the statement: ")


str2 = str.split()
print("Reversed string is: ")

for i in str2[::-1]:
print(i,end=' ')

elif choice == '9':

#Capitalize the first letter of each word


str = input("Enter the statement: ")
print("Original string: \n" + str)
print("Alternatively capitalized string: ")
str2 = str.split()

for i in str2:
i = i.capitalize()
print(i, end=' ')

elif choice == '10':

#Print following pattern


val = 65
n=int(input("Enter number of rows: "))
for i in range(0, n):
for j in range(0, i+1):
ch = chr(val)
print(ch, end=" ")
val = val + 1
print()

elif choice == '11':


print("Exiting the program.")
break

else:
print("Invalid input")

print("Thank you for your kind attention!")

You might also like