[go: up one dir, main page]

0% found this document useful (0 votes)
9 views3 pages

Question 4

Uploaded by

shaurya.mayoor
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)
9 views3 pages

Question 4

Uploaded by

shaurya.mayoor
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/ 3

Question 4

def create():

f=open('myfile.txt','w')
Output
s=input('enter string: ') main menu-

f.write(s) 1.create histogram:

f.close() 2.to do various function on histogram:

f=open('myfile.txt','r') 3.create a dictionary containing length greater than


specified character length:
s=f.read()
4.to find the longest word:
d={}
5. words having length greater than specified character
for i in s.split(): length:

if i not in d: enter your choice: 1

d[i]=s.count(i) enter string: hello hello hi hi how are you hope you are are
correct
print('the histrogram is: ')
the histrogram is: do you want to continue: y
print(d)
{'hello': 2, 'hi': 2, 'how': 1, 'are': 3, 'you': 2, 'hope': 1,
return(d) 'correct': 1}

f.close() main menu-

1.create histogram:

def dofunction(d): 2.to do various function on histogram:

print('function menu-') 3.create a dictionary containing length greater than


specified character length:
print('1.Total number of words')
4.to find the longest word:
print('2.Number of different words')
5. words having length greater than specified character
print('3.The most common words') length:
op=int(input('enter your choice: ')) enter your choice: 2
if op==1:
enter string: hello hello hi hi how are you hope you are are
correct
c=0
the histrogram is:
print('Total number of words is:')
{'hello': 2, 'hi': 2, 'how': 1, 'are': 3, 'you': 2, 'hope': 1,
for i in d:
'correct': 1}
c+=d
function menu-
print(c)
1.Total number of words
elif op==2:
2.Number of different words
print('Number of different words')
3.The most common words
print(len(d))
enter your choice: 2
elif op==3:
Number of different words
print('The most common word')
7
l=[]
do you want to continue:y
for i in d:

l.append(d[i])
main menu-

a=max(i) 1.create histogram:

for i in d: 2.to do various function on histogram:

if d[i]==int(a): 3.create a dictionary containing length greater than


specified character length:
print(d)
4.to find the longest word:
break
5. words having length greater than specified character
length:

def lend(): enter your choice: 3

f=open('myfile.txt','r') {5: ['hello', 'hello'], 2: ['hi', 'hi'], 3: ['how', 'are', 'you', 'you',
'are', 'are'], 4: ['hope'], 7: ['correct']}
d={}
do you want to continue: y
s=f.read()
main menu-
o=s.split()
1.create histogram:
temp=s.split()
2.to do various function on histogram:
for i in temp:
3.create a dictionary containing length greater than
l=[]
specified character length:
for j in o:
4.to find the longest word:
a=len(i)
5. words having length greater than specified character
b=len(j) length:

if b==a: enter your choice: 4

l.append(j) {5: ['hello', 'hello'], 2: ['hi', 'hi'], 3: ['how', 'are', 'you', 'you',
'are', 'are'], 4: ['hope'], 7: ['correct']}
d[a]=l
The longest word is: ['correct']
print(d)
do you want to continue: y
return(d)
main menu-
f.close()
1.create histogram:

2.to do various function on histogram:


def findlongestword():
3.create a dictionary containing length greater than
d=lend() specified character length:

maxi=0 4.to find the longest word:

l={} 5. words having length greater than specified character


length:
for i in d:
enter your choice: 5
if i>maxi:
{5: ['hello', 'hello'], 2: ['hi', 'hi'], 3: ['how', 'are', 'you', 'you',
maxi=i 'are', 'are'], 4: ['hope'], 7: ['correct']}

l=d[i] Enter the length: 2

print('The longest word is: ',l) The list of words having word length greater than 2 is:

[['how', 'are', 'you', 'you', 'are', 'are']]

def listaccording(): do you want to continue: no

d=lend()

n=int(input('Enter the length: '))

l=[]
for i in d:

if len(d[i])>n:

l.append(d[i])

print('The list of words having word length greater than ',n,'is: ')

print(l)

ch='y'

while ch=='y':

print('main menu- ')

print('1.create histogram: ')

print('2.to do various function on histogram: ')

print('3.create a dictionary containing length greater than specified character length: ')

print('4.to find the longest word: ')

print('5. words having length greater than specified character length: ')

op=int(input('enter your choice: '))

if op==1:

create()

elif op==2:

dofunction(create())

elif op==3:

lend()

elif op==4:

findlongestword()

elif op==5:

listaccording()

else:

print('wrong option')

break

ch=input('do you want to continue: ')

You might also like