Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

19-5-2023

Friday, May 19, 2023 6:05 PM

Write a program to find number of occurrences of each letter present in


the given string.

AAABBC

A occurred 3 times Flow of execution


B occurred 2 times
C occurred 1 times word=AAABBC
d={}
d[x]=d.get(x,0)+1
word=input("Enter any word:") d[A]=d.get(A,0)+1
d={} d[A]=0+1
for x in word: d[A]=1
d[x]=d.get(x,0)+1 d={'A':1}
for k,v in d.items():
print(k,"occurred", v, "times") d={'A':1}
x=A
output: d[x]=d.get(x,0)+1
D:\>python program1.py d[x]=d.get(A,0)+1
Enter any word:AABBC d[x]=1+1
A occurred 2 times d[A]=2
B occurred 2 times d={'A':2}
C occurred 1 times
d={'A':2}
D:\>python program1.py x=A
Enter any word:APPLE d[x]=d.get(x,0)+1
A occurred 1 times d[A]=d.get(A,0)+1
P occurred 2 times d[A]=2+1
L occurred 1 times d[A]=3
E occurred 1 times d={'A':3}

D:\>python program1.py d={'A':3}


Enter any word:PYTHON x=B
P occurred 1 times d[x]=d.get(x,0)+1
Y occurred 1 times d[B]=d.get(B,0)+1
T occurred 1 times d[B]=0+1
H occurred 1 times d[B]=1
O occurred 1 times d={'A':3,'B':1}
N occurred 1 times

D:\> d={'A':3,'B':1}
x=B
d[x]=d.get(x,0)+1
d[B]=d.get(B,0)+1
d[B]=1+1
d[B]=2
d={'A':3,'B':2}

python 6pm Page 1


d[B]=2
d={'A':3,'B':2}

d={'A':3,'B':2}
x=C
d[x]=d.get(x,0)+1
d[C]=d.get(C,0)+1
d[C]=0+1
d[C]=1
d={'A':3,'B':2,'C':1}

for k,v in d.items():


print(k,"occurred", v, "times")

A occurred 3 times
B occurred 2 times
C occurred 1 times

Assignment:

Write a program to find number of occurrences of each vowel present in the


given string by using dictionary

Sample output:

apple

a occurred 1 time
e occurred 1 time

python

o occurred 1 time

Write a program to accept student name and Mark from the keyboard and
create a dictionary . Also display student Marks by taking student name as
input.

Program:

n=int(input("Enter the number of students:"))


d={}
for i in range(n):
name=input("Enter student name:")
marks=int(input("Enter student marks:"))
d[name]=marks {'suresh':96,'krishna':88,'kumar':99,'kiran':45,'srinivas':98}
while True:
name=input("Enter student name to get marks:")
marks=d.get(name,-1)
python 6pm Page 2
marks=d.get(name,-1)
if marks==-1:
print("Student not found")
else:
print("The marks of", name,"are",marks)
option=input("Do you want to find another student marks[yes|no]")
if option=='no':
break
print("Thank you for using this application")

output:

D:\>python program1.py
Enter the number of students:5
Enter student name:suresh
Enter student marks:96
Enter student name:krishna
Enter student marks:88
Enter student name:kumar
Enter student marks:99
Enter student name:kiran
Enter student marks:45
Enter student name:srinivas
Enter student marks:98
Enter student name to get marks:kiran
The marks of kiran are 45
Do you want to find another student marks[yes|no]yes
Enter student name to get marks:kumar
The marks of kumar are 99
Do you want to find another student marks[yes|no]yes
Enter student name to get marks:praveen
Student not found
Do you want to find another student marks[yes|no]No
Thank you for using this application

Mini project

Online quiz

q1='''Is python case sensitive when dealing with identifiers?


a.yes
b.No
c.Machine Indpendent
d.None'''
q2='''Which of the following is not a keyword?
a.eval
b.assert
c.local
d.pass'''
q3='''which one of these is a floor division operator?
a./
python 6pm Page 3
a./
b.//
c.%
d.None'''
q4='''What is the output of this 3*1**3?
a.27
b.9
c.3
d.1'''
questions={q1:"a",q2:"a",q3:"b",q4:"c"}
name=input("Enter your name:")
print("Hello", name ,"Welcome to the Quiz")
score=0
for i,j in questions.items():
print()
print(i)
option=input("Do you want to skip this question(yes/no):")
if option=="yes":
continue
ans=input("Enter your answer(a/b/c/d):")
if ans==questions[i]:
print("Correct answer, you got 1 point")
score=score+1
print("Current score is:",score)
else:
print("Wrong answer you lost 1 point")
print("Current score is:",score)
print("Final score is:",score)

output:

D:\>python program1.py
Enter your name:suresh
Hello suresh Welcome to the Quiz

Is python case sensitive when dealing with identifiers?


a.yes
b.No
c.Machine Indpendent
d.None
Do you want to skip this question(yes/no):no
Enter your answer(a/b/c/d):a
Correct answer, you got 1 point
Current score is: 1

Which of the following is not a keyword?


a.eval
b.assert
c.local
d.pass
Do you want to skip this question(yes/no):no
Enter your answer(a/b/c/d):a
python 6pm Page 4
Enter your answer(a/b/c/d):a
Correct answer, you got 1 point
Current score is: 2

which one of these is a floor division operator?


a./
b.//
c.%
d.None
Do you want to skip this question(yes/no):no
Enter your answer(a/b/c/d):b
Correct answer, you got 1 point
Current score is: 3

What is the output of this 3*1**3?


a.27
b.9
c.3
d.1
Do you want to skip this question(yes/no):no
Enter your answer(a/b/c/d):c
Correct answer, you got 1 point
Current score is: 4
Final score is: 4

D:\>

python 6pm Page 5

You might also like