Answer:
See Explaination
Step-by-step explanation:
def process_string(s):
global char#global varibles
char=[]
global count
count=[]
for i in s:
#checking whether i is alphabet or not
if(i.isalpha()):
#converting to lower
i=i.lower()
if i in char:
#if char already present increment count
count[char.index(i)]+=1
else:
#if char not present append it to list
char.append(i)
count.append(1)
#menu
print("1. Enter a string")
print("2. Display the string")
print("3. Reverse the string")
print("4. Append a string to the existing one")
print("5. Slice the string")
print("6. Display the number of occurences of each letter")
print("7. Quit")
op=input("Enter option:")
#as I don't know what you have covered
#I am trying to make it simple
#checking whether input is numeric or not
#you can use try except if you want
while(not op.isnumeric()):
op=input("Enter valid option:")
op=int(op)
global x
while(op!=7):
if(op==1):
x=input("Enter a string: ")
elif(op==2):
print("The string is:",x)
elif(op==3):
x=x[::-1]#reversing the string
print("The string is:",x)
elif(op==4):
y=input("Enter a string: ")
x=x+y #string concatnation
elif(op==5):
a=input("Enter first integer: ")
while(not a.isnumeric()):
a=input("Enter valid first integer: ")
a=int(a)
b=input("Enter second integer: ")
while(not b.isnumeric()):
b=input("Enter valid second integer: ")
b=int(b)
x=x[a:b]#string slicing
#you can also use x.slice(a,b)
elif(op==6):
process_string(x)
for i in range(len(char)):
print(char[i],",",count[i])
else:
#incase of invalid input
print("Invalid option")
print("1. Enter a string")
print("2. Display the string")
print("3. Reverse the string")
print("4. Append a string to the existing one")
print("5. Slice the string")
print("6. Display the number of occurences of each letter")
print("7. Quit")
op=input("Enter option:")
while(not op.isnumeric()):
op=input("Enter valid option:")
op=int(op)