MENU BASED PROGRAM (2)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 37

#MENU BASED PROGRAM(STRINGS)

#1.FUNCTON TO DISPLAY WORDS STARTING WITH GIVEN LETTER

def countwards(s,ch):

ctr=0

l=s.split()

print('WORDS STARTING WITH',ch)

for i in l:

if i[0].upper()==ch.upper():

print(i)

ctr=ctr+1

print('NO OF WORDS STARTING WITH',ch,'are',ctr)

#2.FUNCTION TO DISPLAY GIVEN SENTENCE IN REVERSE ORDER

def reverse(s):

l=s.split()

l=l[::-1]

for i in l:

print(i,end='')

#3.FUNCTION TO DISPLAY LONGEST WORD

def longest(line):

s=line.split()

z=len(s[0])

y=s[0]

for i in range(1,len(s)):

if len(s[i])>z:

z=len(s[i])

y=s[i]

print(z)

print(y)
#4.FREQUENCY OF ALL ALPHABETS IN THE LINE

def frequency (line):

d={}

n=''

for i in line:

if i.isalpha():

n=n+i

n=n.upper()

for a in n:

if a in d:

d[a]=d[a]+1

else:

d[a]=1

print('CHARACTER\tFREQUENCY')

for b in d:

print(b,'\t\t',d[b])

#5.FUNCTION TO REPLACE A VOWEL

def replacevowel(word):

z=''

l=len(word)

for i in range(l):

if word[i] in 'AEIOUaeiou':

x=ord(word[i])

x=x+1

x=chr(x)

z=z+x

else:

z=z+word[i]

print(z)

#6.FUNCTION TO CONVERT INTO PIGLATIN


def piglatin(line):

l=line.split()

print('WORD' '\t \t' 'PIGLATION')

for word in l:

for i in range(len(word)):

if word[i]in 'AEIOUaeiou':

pword=word[i:]+word[:i]+'AY'

break

else:

pword=word+'AY'

print(word,'\t' '\t',pword)

#7.FUNCTION FOR PALINDROME

def palindrome(line):

l=line.split()

print('WORD' '\t\t' 'PALINDROME')

for a in l:

if a==a[::-1]:

print(a,'\t\t' 'YES')

else:

print(a,'\t\t' 'NO')

#8.FUNCTION FOR FREQUENCY TABLE

def frequencytable(line):

d={}

n=''

for a in line:

if a.isdigit():

n=n+1

n=n.upper()

for k in n:

if k in d:

d[k]=d[k]+1
else:

d[k]=1

print('DIGIT\t\tFREQUENCY')

for j in d:

print(j,'\t\t',d[k])

print('\t\t' 'MAIN MENU' '\t \t')

def menu():

while True:

print('1:DISPLAY LETTERS WITH GIVEN ALPHABET')

print('2:DISPLAY SENTENCE IN REVERSE ORDER')

print('3:DISPLAY LONGEST WORD IN THE SENTENCE')

print('4:FREQUENCY OF ALL ALPHABETS')

print('5:REPLACE A VOWEL')

print('6:CONVERT INTO PIGLATION FORM')

print('7:PALINDROME WORDS')

print('8:FREQUENCY TABLE')

print('9:EXIT')

op=int(input('ENTER THE CHOICE:'))

if op==1:

s=input('ENTER THE SENTENCE:')

ch=input('ENTER ALPHABET:')

countwards(s,ch)

elif op==2:

s=input('ENTER SENTENCE:')

reverse(s)

elif op==3:

line=input('ENTER THE SENTENCE:')

longest(line)

elif op==4:

line=input('ENTER THE SENTENCE:')

frequency(line)
elif op==5:

word=input('ENTER THE WORD:')

replacevowel(word)

elif op==6:

line=input('ENTER THE SENTENCE:')

piglatin(line)

elif op==7:

line=input('ENTER THE SENTENCE:')

palindrome(line)

elif op==8:

line=input('ENTER THE SENTENCE:')

frequencytable(line)

else:

break

menu()
output

MAIN MENU

1: DISPLAY LETTERS WITH GIVEN ALPHABET

2: DISPLAY SENTENCE IN REVERSE ORDER

3: DISPLAY LONGEST WORD IN THE SENTENCE

4: FREQUENCY OF ALL ALPHABETS

5: REPLACE A VOWEL

6: CONVERT INTO PIGLATION FORM

7: PALINDROME WORDS

8: FREQUENCY TABLE

9: EXIT

ENTER THE CHOICE:1

ENTER THE SENTENCE: THIS IS TAJ MAHAL

ENTER ALPHABET:T

WORDS STARTING WITH T

THIS
TAJ

NO OF WORDS STARTING WITH T are 2

[19:56, 5/21/2023] Jaskirat: MAIN MENU

1: DISPLAY LETTERS WITH GIVEN ALPHABET

2: DISPLAY SENTENCE IN REVERSE ORDER

3: DISPLAY LONGEST WORD IN THE SENTENCE

4: FREQUENCY OF ALL ALPHABETS

5: REPLACE A VOWEL

6: CONVERT INTO PIGLATION FORM

7: PALINDROME WORDS

8: FREQUENCY TABLE

9: EXIT

ENTER THE CHOICE:2

ENTER SENTENCE: THIS IS A BOOK

1: DISPLAY LETTERS WITH GIVEN ALPHABET

2: DISPLAY SENTENCE IN REVERSE ORDER


3:DISPLAY LONGEST WORD IN THE SENTENCE

4: FREQUENCY OF ALL ALPHABETS

5: REPLACE A VOWEL

6: CONVERT INTO PIGLATION FORM

7: PALINDROME WORDS

8: FREQUENCY TABLE

9: EXIT

ENTER THE CHOICE:3

ENTER THE SENTENCE: FIND THE CORRECT STATEMENT

STATEMENT

1: DISPLAY LETTERS WITH GIVEN ALPHABET 2: DISPLAY SENTENCE IN REVERSE ORDER

3:DISPLAY LONGEST WORD IN THE SENTENCE

4: FREQUENCY OF ALL ALPHABETS

5: REPLACE A VOWEL

6: CONVERT INTO PIGLATION FORM


7: PALINDROME WORDS

8: FREQUENCY TABLE

9: EXIT

ENTER THE CHOICE: 4

ENTER THE SENTENCE: CORRECT STATEMENT IS

CHARACTER

FREQUENCY

REES T

AMNH
1

1: DISPLAY LETTERS WITH GIVEN ALPHABET 2: DISPLAY SENTENCE IN REVERSE ORDER

3:DISPLAY LONGEST WORD IN THE SENTENCE

4: FREQUENCY OF ALL ALPHABETS

5: REPLACE A VOWEL

6: CONVERT INTO PIGLATION FORM

7: PALINDROME WORDS

8: FREQUENCY TABLE

9:EXIT

ENTER THE CHOICE:5

ENTER THE WORD: INTERESTING

JN

JNT
JNTF

JNTFR

JNTFRF

JNTFRFS

JNTFRFST

JNTFRFSTJ

JNTFRFSTJN

JNTFRFSTJNG

: 1: DISPLAY LETTERS WITH GIVEN ALPHABET

2: DISPLAY SENTENCE IN REVERSE ORDER 3:DISPLAY LONGEST WORD IN THE SENTENCE

4: FREQUENCY OF ALL ALPHABETS

5: REPLACE A VOWEL

6: CONVERT INTO PIGLATION FORM

7: PALINDROME WORDS

8: FREQUENCY TABLE

9: EXIT
ENTER THE CHOICE:7

ENTER THE SENTENCE: MADAM IS TEACHING

WORD

PALINDROME

MADAM

YES

IS

NO

TEACHING

1: DISPLAY LETTERS WITH GIVEN ALPHABET

2: DISPLAY SENTENCE IN REVERSE ORDER

3: DISPLAY LONGEST WORD IN THE SENTENCE

4: FREQUENCY OF ALL ALPHABETS

5: REPLACE A VOWEL

6: CONVERT INTO PIGLATION FORM


7: PALINDROME WORDS

8: FREQUENCY TABLE

9: EXIT

ENTER THE CHOICE: 6

ENTER THE SENTENCE: THIS IS MY BOOK

WORD

PIGLATION

THIS

ISTHAY

IS

ISAY

MY

MYAY

BOOK

OOKBAY
MENU BASED PROGRAM FOR LISTS

def greattwo(l):

n=[]

for i in l:

if len(str(i))==2:

n.append(i)

n.sort(reverse=True)

print("Greatest two digit number is:",n[0])

print("Sum of two digit number:",sum(n))

def check(s):

import statistics as x

print('HIHEST:',max(s))

print('LOWEST:',min(s))

print('MEAN:',x.mean(s))

print('MEDIAN:',x.median(s))

print('MODE:',x.mode(s))

def alpha(s):

alp=input('ENTER THE LETTER:')

while (len(alp))!=1:

alp= input('ENTER THE LETTER:')

print('LETTER BEGINNING WITH',alp,'ARE:')

for i in l:

if[0].upper()==let.upper():

print(i)

def shift(l):

i=0

j=len(l)-1

while i<j:

while l[i]%2==0:

i=i+1
while l[j]%2!=0:

j=j-1

if i<j:

l[i],l[j]=l[j],l[i]

print(l)

l=[]

def ascend(L):

print('ORIGINAL LIST',L)

L.sort()

print('LIST IN ASCENDING ORDER',L)

L.sort(reverse=True)

print('LIST IN DESCENDING ORDER:',L)

print('FIRST TWO HIGHEST:',L[0],L[1])

print('FIRST TWO LOWEST:',L[-1],L[-2])

def even(l):

print('ORIGININAL LIST;',l)

for i in l:

if i%2==0:

l.remove(i)

print('UPDATED LIST:',l)

def update(l):

a=len(l)

for i in range(a):

if l[i]>0:

l[i]=l[i]*2

else:

l[i]=l[i]+5

print('UPDATED LIST:',l)

print('\t\t' 'MAIN MENU' '\t \t')

def menu():
while True:

print('1:GREATEST TWO DIGIT NUMBER')

print('2:HIGHEST,LOWEST')

print('3:WORDS WITH GIVEN LETTER')

print('4:SHIFT NUMBERS')

print('5:ASCENDING DESCENDING ORDER')

print('6:REMOVE EVEN NO')

print('7:MULTIPLY POSITIVE NO')

print('8:EXIT')

op=int(input('ENTER THE CHOICE:'))

if op==1:

l=[]

n=int(input('HOW MANY NUMBERS:'))

for i in range (n):

no=int(input('ENTER NO :'))

l.append(no)

greattwo(l)

elif op==2:

s=[]

n=int(input('HOW MANY NUMBERS:'))

for i in range (n):

no=int(input('ENTER NO :'))

s.append(no)

check(s)

elif op==3:

l=[]

s=input('ENTER SENTENCE:')

alpha(s)

elif op==4:

l=[]
n=int(input('HOW MANY NUMBERS:'))

for i in range (n):

no=int(input('ENTER NO :'))

l.append(no)

shift(l)

elif op==5:

l=[]

n=int(input('HOW MANY NUMBERS:'))

for i in range (n):

no=int(input('ENTER NO :'))

l.append(no)

ascend(l)

elif op==6:

l=[]

n=int(input('HOW MANY NUMBERS:'))

for i in range (n):

no=int(input('ENTER NO :'))

l.append(no)

even(l)

elif op==7:

l=[]

n=int(input('HOW MANY NUMBERS:'))

for i in range (n):

no=int(input('ENTER NO :'))

l.append(no)

update(l)

else:

break

menu()
output

1) MAIN MENU

1:GREATEST TWO DIGIT NUMBER

2:HIGHEST,LOWEST

3:WORDS WITH GIVEN LETTER

4:SHIFT NUMBERS

5:ASCENDING DESCENDING ORDER

6:REMOVE EVEN NO

7:MULTIPLY POSITIVE NO

8:EXIT

ENTER THE CHOICE:1

HOW MANY NUMBERS:5

ENTER NO :45

ENTER NO :34

ENTER NO :56

ENTER NO :23

ENTER NO :19

Greatest two digit number is: 56

Sum of two digit number: 177

2) MAIN MENU

1:GREATEST TWO DIGIT NUMBER

2:HIGHEST,LOWEST

3:WORDS WITH GIVEN LETTER

4:SHIFT NUMBERS

5:ASCENDING DESCENDING ORDER

6:REMOVE EVEN NO

7:MULTIPLY POSITIVE NO

8:EXIT

ENTER THE CHOICE:2


HOW MANY NUMBERS:4

ENTER NO :48

ENTER NO :97

ENTER NO :69

ENTER NO :87

HIHEST: 97

LOWEST: 48

MEAN: 75.25

MEDIAN: 78.0

MODE: 48

3) MAIN MENU

1:GREATEST TWO DIGIT NUMBER

2:HIGHEST,LOWEST

3:WORDS WITH GIVEN LETTER

4:SHIFT NUMBERS

5:ASCENDING DESCENDING ORDER

6:REMOVE EVEN NO

7:MULTIPLY POSITIVE NO

8:EXIT

ENTER THE CHOICE:4

HOW MANY NUMBERS:6

ENTER NO :23

ENTER NO :46

ENTER NO :56

ENTER NO :79

ENTER NO :88

ENTER NO :45

[88, 46, 56, 79, 23, 45]

4) MAIN MENU

1:GREATEST TWO DIGIT NUMBER


2:HIGHEST,LOWEST

3:WORDS WITH GIVEN LETTER

4:SHIFT NUMBERS

5:ASCENDING DESCENDING ORDER

6:REMOVE EVEN NO

7:MULTIPLY POSITIVE NO

8:EXIT

ENTER THE CHOICE:5

HOW MANY NUMBERS:6

ENTER NO :24

ENTER NO :56

ENTER NO :79

ENTER NO :87

ENTER NO :65

ENTER NO :45

ORIGINAL LIST [24, 56, 79, 87, 65, 45]

LIST IN ASCENDING ORDER [24, 45, 56, 65, 79, 87]

LIST IN DESCENDING ORDER: [87, 79, 65, 56, 45, 24]

FIRST TWO HIGHEST: 87 79

FIRST TWO LOWEST: 24 45

6) MAIN MENU

1:GREATEST TWO DIGIT NUMBER

2:HIGHEST,LOWEST

3:WORDS WITH GIVEN LETTER

4:SHIFT NUMBERS

5:ASCENDING DESCENDING ORDER

6:REMOVE EVEN NO

7:MULTIPLY POSITIVE NO

8:EXIT

ENTER THE CHOICE:6


HOW MANY NUMBERS:6

ENTER NO :23

ENTER NO :44

ENTER NO :64

ENTER NO :76

ENTER NO :55

ENTER NO :89

ORIGININAL LIST; [23, 44, 64, 76, 55, 89]

UPDATED LIST: [23, 64, 55, 89]

7) MAIN MENU

1:GREATEST TWO DIGIT NUMBER

2:HIGHEST,LOWEST

3:WORDS WITH GIVEN LETTER

4:SHIFT NUMBERS

5:ASCENDING DESCENDING ORDER

6:REMOVE EVEN NO

7:MULTIPLY POSITIVE NO

8:EXIT

ENTER THE CHOICE:7

HOW MANY NUMBERS:6

ENTER NO :67

ENTER NO :-32

ENTER NO :-43

ENTER NO :-41

ENTER NO :23

ENTER NO :67

UPDATED LIST: [134, -27, -38, -36, 46, 134]


MENU BASED PROGRAMS(DICTIONARY)

#COUNTRY AND CAPITAL

def countcapt():

d={}

n=int(input('HOW MANY VALUES:'))

for i in range(n):

cntry=input('ENTER COUNTRY NAME:\t')

capt=input('ENTER CAPITAL NAME:\t')

d[cntry.upper()]=capt.upper()

print('S No \t COUNTRY NAME \t CAPITAL')

ctr=1

for count in d:

print(ctr,'\t',count,'\t',d[count])

ctr=ctr+1

c=input('ENTER COUNTRY NAME TO BE SEARCHED:')

if c.upper() in d:

print('CAPITAL OF',c,'is',d[c.upper()])

else:

cap=input('ENTER CAPITAL:\t')

d[c.upper()]=cap.upper()

#STUDENT DATA

def student():

d={}

n=int(input("Enter how many students:"))

for i in range(n):

admn=int(input("Enter Addmission number:"))

name=input(…
CHOICE:1

HOW MANY VALUES:5

ENTER COUNTRY NAME: INDIA

ENTER CAPITAL NAME: DELHI

ENTER COUNTRY NAME: UNITED STATES OF AMERICA

ENTER CAPITAL NAME: WASHINGTON D.C

ENTER COUNTRY NAME: CHINA

ENTER CAPITAL NAME: BEIJING

ENTER COUNTRY NAME: AUSTRALIA

ENTER CAPITAL NAME: CANBERRA

ENTER COUNTRY NAME: CANADA

ENTER CAPITAL NAME: OTTAWA

S No COUNTRY NAME CAPITAL

1 INDIA DELHI

2 UNITED STATES OF AMERICA WASHINGTON D.C

3 CHINA BEIJING

4 AUSTRALIA CANBERRA

5 CANADA OTTAWA

ENTER COUNTRY NAME TO BE SEARCHED:INDIA

CAPITAL OF INDIA is DELHI

2) MAIN MENU

1:COUNTRY AND CAPITAL

2:STUDENTS DATA

3:MONTHS AND DAYS

4:EMPLOYES DATA

5:EXIT

ENTER THE CHOICE:1

HOW MANY VALUES:5

ENTER COUNTRY NAME: INDIA


ENTER CAPITAL NAME: DELHI

ENTER COUNTRY NAME: UNITED STATES OF AMERICA

ENTER CAPITAL…

You might also like