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

Grade 11 C. Sc. Menu-driven Programs[1]

The document outlines multiple menu-driven programs for various operations such as managing a contact list, performing list operations, analyzing a sentence, and mathematical computations on numbers. Each program includes options for user input and specific functionalities like adding, modifying, deleting, and displaying data. The programs are designed to enhance programming skills in Python through practical applications of data structures and algorithms.

Uploaded by

vedantvj23
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)
2 views

Grade 11 C. Sc. Menu-driven Programs[1]

The document outlines multiple menu-driven programs for various operations such as managing a contact list, performing list operations, analyzing a sentence, and mathematical computations on numbers. Each program includes options for user input and specific functionalities like adding, modifying, deleting, and displaying data. The programs are designed to enhance programming skills in Python through practical applications of data structures and algorithms.

Uploaded by

vedantvj23
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
You are on page 1/ 15

Grade 11 C. Sc.

Menu-driven Programs

Write a program to input your friends’ names and their Phone Numbers and store them
in the dictionary as the key-value pair. Perform the following operations on the
dictionary:
a) Display the name and phone number of all your friends
b) Add a new key-value pair in this dictionary and display the modified dictionary
c) Delete a particular friend from the dictionary
d) Modify the phone number of an existing friend
e) Check if a friend is present in the dictionary or not
f) Display the dictionary in sorted order of names
g) Exit

dic = {}
#Creates an empty dictionary
#While loop to provide the options repeatedly
#it will exit when the user enters 7
while True:
print("1. Add New Contact")
print("2. Modify Phone Number of Contact")
print("3. Delete a Friend's contact")
print("4. Display all entries")
print("5. Check if a friend is present or not")
print("6. Display in sorted order of names")
print("7. Exit")
inp = int(input("Enter your choice(1-7): "))
#Adding a contact
if(inp == 1):
name = input("Enter your friend name: ")
phonenumber = input("Enter your friend's contact number: ")
dic[name] = phonenumber
print("Contact Added \n\n")
#Modifying a contact if the entered name is present in the dictionary
elif(inp == 2):
name = input("Enter the name of friend whose number is to be modified: ")
if(name in dic):
phonenumber = input("Enter the new contact number: ")
dic[name] = phonenumber
print("Contact Modified\n\n")
else:
print("This friend's name is not present in the contact list")
#Deleting a contact if the entered name is present in the dictionary
elif(inp == 3):
name = input("Enter the name of friend whose contact is to be deleted: ")
if(name in dic):
del dic[name]
print("Contact Deleted\n\n")
else:
print("This friend's name is not present in the contact list")
#Displaying all entries in the dictionary
elif(inp == 4):
print("All entries in the contact")
for a in dic:
print(a,"\t\t",dic[a])
print("\n\n\n")
#Searching a friend name in the dictionary
elif(inp == 5):
name = input("Enter the name of friend to search: ")
if(name in dic):
print("The friend",name,"is present in the list\n\n")
else:
print("The friend",name,"is not present in the list\n\n")
#Displaying the dictionary in the sorted order of the names
elif(inp == 6):
print("Name\t\t\tContact Number")
for i in sorted(dic.keys()):
print(i,"\t\t\t",dic[i])
print("\n\n")
#Exit the while loop if user enters 7
elif(inp == 7):
break
#Displaying the invalid choice when any other values are entered
else:
print("Invalid Choice. Please try again\n")
Write a menu driven program to perform various list operations, such as:
• Append an element
• Insert an element
• Append a list to the given list
• Modify an existing element
• Delete an existing element from its position
• Delete an existing element with a given value
• Sort the list in ascending order
• Sort the list in descending order
• Display the list.
• Exit

#Program
#Menu driven program to do various list operations
myList = [] #[22,4,16,38,13] #myList
n=int(input("Enter number of students : "))
for i in range(n):
num=int(input("Enter a number: "))
myList.append(num)
choice = 0
while True:
print("The list 'myList' has the following elements", myList)
print("\n MENU LIST OPERATIONS")
print(" 1. Append an element")
print(" 2. Insert an element at the desired index position")
print(" 3. Append a list to the given list")
print(" 4. Modify an existing element")
print(" 5. Delete an existing element by its position")
print(" 6. Delete an existing element by its value")
print(" 7. Sort the list in ascending order")
print(" 8. Sort the list in descending order")
print(" 9. Display the list")
print(" 10. Exit")
choice = int(input("ENTER YOUR CHOICE (1-10): "))
#append element
if choice == 1:
element = int(input("Enter the element to be appended: "))
myList.append(element)
print("The element has been appended\n")
#insert an element at desired position
elif choice == 2:
element = int(input("Enter the element to be inserted: "))
pos = int(input("Enter the index for inserting: "))
myList.insert(pos,element)
print("The element has been inserted\n")
#append a list to the given list
elif choice == 3:
newList=[]
n=int(input("Enter number of elements in new list: "))
for i in range(n):
num= int(input("Enter a number to be appended: "))
newList.append(num)
myList.extend(newList)
print("The list has been appended\n")
#modify an existing element
elif choice == 4:
i = int(input("Enter the index of the element to be modified: "))
if i < len(myList):
newElement = int(input("Enter the new element: "))
oldElement = myList[i]
myList[i] = newElement
print("The element",oldElement,"has been modified\n")
else:
print("Position of the element is more than the length of list")
#delete an existing element by position
elif choice == 5:
i = int(input("Enter the index of the element to be deleted: "))
if i < len(myList):
element = myList.pop(i)
print("The element",element,"has been deleted\n")
else:
print("\nIndex of the element is more than the length of list")
#delete an existing element by value
elif choice == 6:
element = int(input("\nEnter the element to be deleted: "))
if element in myList:
myList.remove(element)
print("\nThe element",element,"has been deleted\n")
else:
print("\nElement",element,"is not present in the list")
#list in sorted order
elif choice == 7:
myList.sort()
print("\nThe list has been sorted")
#list in reverse sorted order
elif choice == 8:
myList.sort(reverse = True)
print("\nThe list has been sorted in reverse order")
#display the list
elif choice == 9:
print("\nThe list is:", myList)
#exit from the menu
elif choice == 10:
break
else:
print("Choice is not valid")
print("\n\nPress any key to continue..............")
ch = input()
Write a Menu-driven program to input a sentence and perform the following
operations:
1. Count number of characters.
2. Count number of capital letters
3. Count number of small letters
4. Count number of blank spaces
5. Count number of digits
6. Count number of special or other characters
7. Number of alphabets
8. Number alphanumeric characters
9. Number of words
10. Exit

s=input("Enter a sentence: ")


choice=0
while True:
print("********MAIN MENU*********")
print("--------------------------")
print("1. Count number of characters")
print("2. Count number of capital letters")
print("3. Count number of small letters")
print("4. Count of blank spaces")
print("5. Count number of digits")
print("6. Count number of special or other characters")
print("7. Count Number of alphabets")
print("8. Count Number of alphanumeric characters")
print("9. Count number of words")
print("10. Exit")
print("--------------------------")
choice=int(input("Enter your choice (1..10): "))
if choice==1:
print("Given string: ", s)
L=len(s)
print("Number of characters=",L)
elif choice==2:
print("Given string: ", s)
caps=0
for i in range(len(s)):
if s[i].isupper():
caps+=1
print("Number of capital letters=",caps)
elif choice==3:
print("Given string: ", s)
small=0
for i in range(len(s)):
if s[i].islower():
small+=1
print("Number of small letters=",small)
elif choice==4:
print("Given string: ", s)
space=0
for i in range(len(s)):
if s[i].isspace():
space+=1
print("Number of blank spaces=",space)
elif choice==5:
print("Given string: ", s)
digit=0
for i in range(len(s)):
if s[i].isdigit():
digit+=1
print("Number of digits=",digit)
elif choice==6:
print("Given string: ", s)
Others=0
for i in range(len(s)):
if s[i].isalnum()==False and s[i].isspace()==False:
Others+=1
print("Number of other / special characters=",Others)
elif choice==7:
print("Given string: ", s)
Alpha=0
for i in range(len(s)):
if s[i].isalpha():
Alpha+=1
print("Number of alphabets=",Alpha)
elif choice==8:
print("Given string: ", s)
alno=0
for i in range(len(s)):
if s[i].isalnum():
alno+=1
print("Number of alphanumric characters=",alno)
elif choice==9:
print("Given string: ", s)
words=0
words=len(s.split())
print("Number of blank words=",words)
elif choice==10:
print("Ending the program !")
exit()
else:
print("Invalid Choice!")
Write a menu driven program to perform the following operations:

• Find Sum of Digits


• Reverse the number.
• Check if the number is a palindrome.
• Check if the number is an Armstrong number.
• Check if the number is a perfect number.
• Check if the number is a prime number.
• Check if a single digit number is present in a multi - digit number.
• Exit

choice=0
while choice!=8:
print ("*" * 20)
print(" MAIN MENU")
print ("1. Find Sum of Digits")
print ("2. Reverse the number")
print ("3. Check if the number is a palindrome")
print ("4. Check if the number is a armstrong number")
print ("5. Check if the number is a perfect number")
print ("6. Check if the number is a prime number")
print ("7. Check if a single digit number is \
present in a multi - digit number")
print ("8. Exit")
print ("*" * 20)
choice=int(input("Enter your choice(1..8): "))
if choice==1:
n=int(input("Enter a number: "))
N=n
sum1 = 0
while n>0 :
digit = n % 10
sum1 = sum1 + digit
n = n // 10
print ("The number entered = ",N)
print ("Sum of Digits = ",sum1)
elif choice==2:
n=int(input("Enter a number: "))
N=n
reverse = 0
while n>0 :
digit = n % 10
reverse = reverse * 10 + digit
n = n // 10
print ("The original number = ",N)
print ("The reversed number = ",reverse)

elif choice==3:
A=int(input("Enter a number: "))
a=A
r=0
while A>0 :
digit = A % 10
r = r * 10 + digit
A = A // 10
print ("The original number = ",a)
print ("The reverse number = ",r)
if a==r :
print ("The number is palindrome")
else :
print ("The number is not palindrome")

elif choice==4:
A=int(input("Enter a number: "))
a=A
sum1 = 0
while A>0 :
rem = A % 10
sum1 = sum1+ rem ** 3
A = A // 10
print ("The original number = ",a)
print ("The armstrong number = ",sum1)
if a == sum1 :
print ("The number is an armstrong number")
else :
print ("The number is not an armstrong number")
elif choice==5:
n=int(input("Enter a number: "))
i=1
sum = 0
print ("Printing factors of number",n)
while i <= n - 1 :
if n % i == 0:
print (i)
sum = sum + i
i=i+1
print ("The number entered = ",n)
print ("Sum of Factors = ",sum)
if sum == n:
print (n,"is a perfect number")
else:
print (n,"is not a perfect number")

elif choice==6:
n=int(input("Enter a number: "))
prime = 1
for i in range (2, n-1):
if n % i == 0:
prime = 0
if prime == 1:
print (n, "is a prime number")
else:
print (n,"is not a prime number")

elif choice==7:
n=int(input("Enter a single digit number: "))
M=int(input("Enter a multi-digit number: "))
found = 0
m=M
while m > 0 :
digit = m % 10
if digit == n:
found = 1
m = m // 10
if found == 1 :
print (n,"is found in",M)
else :
print (n,"is not found in",M)

elif choice == 8:
print ("Ending program !")
break
else:
print("Invalid choice !")
Write a menu driven program that has options to:
• Input Name of a student and Class & Section
• Accept the marks of the student in five major subjects in Class XI and display the
same.
• Calculate the sum of the marks of all subjects.
Divide the total marks by number of subjects (i.e. 5), calculate percentage = total
marks/5
and display the percentage.
Notes
• Find the grade of the student as per the following criteria:
----------------------------------------------------------------
Criteria Grade
-----------------------------------------------------------------
percentage >= 85 A
percentage < 85 & percentage >= 75 B
percentage < 75 & percentage >= 50 C
percentage >= 30 & percentage < 50 D
percentage <30 Reappear
------------------------------------------------------------------
Display Name and Class & Section
Display Subject and marks in each subject.
Display total Marks
Display the Percentage marks and Grade with suitable headings

choice=0
while choice!=6:
print("---------------------------------------------")
print(" MAIN MENU ")
print("---------------------------------------------")
print("1. Input Name and class & section ")
print("2. Input marks in 5 subjects ")
print("3. Calculate Total Marks and percentage marks")
print("4. Find grade based on percentage mark")
print("5. Display all details")
print("6. Exit")
print("----------------------------------------------")
choice=int(input("Enter your choice: (1..6): "))
if choice==1:
name=input("Enter your name:")
class_n_sec=input("Enter your class & section:")
elif choice==2:
eng=int(input("Enter marks in English:"))
mat=int(input("Enter marks in Mathematics: "))
phy=int(input("Enter marks in Physics: "))
chem=int(input("Enter marks in Chemistry: "))
csc=int(input("Enter marks in Computer Science: "))
elif choice==3:
total=eng+mat+phy+chem+csc
perc=total/500*100
elif choice==4:
if perc>=85 and perc<=100:
Grade="A"
elif perc>=75 and perc<85:
Grade="B"
elif perc>=50 and perc<75:
Grade="C"
elif perc>=30 and perc<50:
Grade="D"
elif perc>=0 and perc<30:
Grade="Reappear"
else:
print("Invalid data!")
elif choice==5:
print("Displaying the details: ")
print("Name:", name)
print("Class and section: ", class_n_sec)
print("Marks in 5 subjects: ")
print("English: ",eng)
print("Mathematics: ",mat)
print("Physics: ",phy)
print("Chemistry: ", chem)
print("Computer Science: ",csc)
print("Total marks=", total)
print("Percentage marks=", perc)
print("Your Grade is: ", Grade)
elif choice==6:
exit()
else:
print("Invalid choice!")

You might also like