0% found this document useful (0 votes)
5 views6 pages

Sample

The document provides a menu-driven program that allows users to manipulate a list, a tuple, and a string through various operations. Users can append, extend, insert, remove elements, sort, and display the list, as well as access elements, count occurrences, and display the tuple. For the string, users can find its length, convert it to uppercase or lowercase, capitalize it, and count occurrences of a substring.

Uploaded by

rakshitmathur19
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)
5 views6 pages

Sample

The document provides a menu-driven program that allows users to manipulate a list, a tuple, and a string through various operations. Users can append, extend, insert, remove elements, sort, and display the list, as well as access elements, count occurrences, and display the tuple. For the string, users can find its length, convert it to uppercase or lowercase, capitalize it, and count occurrences of a substring.

Uploaded by

rakshitmathur19
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

list = [1, 2, 3, 4, 5]

print("\nMenu:")

print("1. Append an element to the list")

print("2. Extend the list with another list")

print("3. Insert an element at a specific index")

print("4. Remove an element by value")

print("5. Remove an element by index")

print("6. Count occurrences of an element")

print("7. Find the index of an element")

print("8. Sort the list in ascending order")

print("9. Reverse the list")

print("10. Display the current list")

print("11. Exit")

while True:

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

if choice == 1:

element = input("Enter an element to append to the list: ")

list.append(element)

elif choice == 2:

new_list = input("Enter a list to extend the current list: ")

list.extend(eval(new_list))

elif choice == 3:

element = input("Enter an element to insert: ")

index = int(input("Enter the index to insert at: "))

list.insert(index, element)

elif choice == 4:

element = input("Enter an element to remove: ")

list.remove(element)
elif choice == 5:

index = int(input("Enter the index to remove: "))

if 0 <= index < len(list):

del list[index]

else:

print("Index out of range.")

elif choice == 6:

element = input("Enter an element to count: ")

count = list.count(element)

print(count)

elif choice == 7:

element = input("Enter an element to find its index: ")

index = list.index(element)

print(element, “is at”, index)

elif choice == 8:

list.sort()

elif choice == 9:

list.reverse()

elif choice == 10:

print(list)

elif choice == 11:

break

else:

print("Invalid choice. Please enter a valid option.")


sample_tuple = (1, 2, 3, 4, 5)

print("\nMenu:")

print("1. Access an element by index")

print("2. Count occurrences of an element")

print("3. Find the index of an element")

print("4. Display the current tuple")

print("5. Exit")

while True:

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

if choice == 1:

index = int(input("Enter the index to access: "))

if 0 <= index < len(sample_tuple):

element = sample_tuple[index]

print(element)

else:

print("Index out of range.")

elif choice == 2:

element = input("Enter an element to count: ")

count = sample_tuple.count(element)

print(count)

elif choice == 3:

element = input("Enter an element to find its index: ")

index = sample_tuple.index(element)

print(index)

elif choice == 4:

print(sample_tuple)

elif choice == 5:
break

else:

print("Invalid choice. Please enter a valid option.")


string = "Hello, World!"

print("\nMenu:")

print("1. Find the length of the string")

print("2. Convert the string to uppercase")

print("3. Convert the string to lowercase")

print("4. Capitalize the string")

print("5. Count occurrences of a substring")

print("6. Display the current string")

print("7. Exit")

while True:

choice = int(input("Enter your choice (1-7): "))

if choice == 1:

length = len(string)

print(length)

elif choice == 2:

uppercase_string = string.upper()

print(uppercase_string)

elif choice == 3:

lowercase_string = string.lower()

print(lowercase_string)

elif choice == 4:

capitalized_string = string.capitalize()

print(capitalized_string)

elif choice == 5:

substring = input("Enter a substring to count: ")

count = string.count(substring)

print(count)

elif choice == 6:
print(string)

elif choice == 7:

break

else:

print("Invalid choice. Please enter a valid option.")

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy