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

Dictinary Assignment

The document outlines various programming tasks involving dictionaries in Python, including storing employee names and salaries, converting numbers to words, counting votes in an election, and managing sports team records. It also includes exercises for merging dictionaries, calculating word and character frequencies, and managing student and hospital data. Each task is designed to enhance understanding of dictionary operations and data management in Python.
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)
2 views3 pages

Dictinary Assignment

The document outlines various programming tasks involving dictionaries in Python, including storing employee names and salaries, converting numbers to words, counting votes in an election, and managing sports team records. It also includes exercises for merging dictionaries, calculating word and character frequencies, and managing student and hospital data. Each task is designed to enhance understanding of dictionary operations and data management in Python.
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

Anil Bhalothia

Programs based on dictionary


1. Write a program to enter names of employees as key and their salaries as value and
store them in a dictionary.
2. Write a program to convert a number entered by user into its corresponding number
in words. For example if the input is 876 then output will be “Eight Seven Six”.
3. Given a list of names of candidates in an election. A candidate name in the list
represents a vote cast to the candidate. Print the name of candidates received Max
vote. If there is tie, print a lexicographically smaller name.
Examples:
Input : votes[] = {"john", "johnny", "jackie", "johnny", "john", "jackie",
"jamie", "jamie", "john", "johnny", "jamie", "johnny", "john"}
Output : John
We have four Candidates with name as 'John', 'Johnny', 'jamie', 'jackie'. The
candidates John and Johny get maximum votes. Since John is alphabetically smaller,
we print it.
4. Repeatedly ask the user to enter a team name and how many games the team has
won and how many they lost. Store this information in a dictionary where the keys
are the team names and the values are lists of the form[wins, losses].
a) Using the dictionary created above, allow the user to enter a team name and
print out the team’s winning percentage.
b) Using the dictionary, create a list whose entries are the number of wins of each
team.
c) Using the dictionary, create a list team names having at least 1 win.
5. Merging two Dictionaries without using update method.
6. Sort Python Dictionaries by Key or Value.
7. Find out frequency of words present in a sentence
8. Find out frequency of characters present in a word
9. Write a program in Python, where , SItem is a dictionary containing the details of
stationary items– {Sname:price}.The program should add the names of those items
in the list who have price greater than 75. Also display the count of elements added
to the list.
For example:
If the dictionary contains the following data:
Sitem={"Pen":106,"Pencil":59,"Notebook":80,"Eraser":25}
The list should contain
Pen
Notebook
The output should be:
Pen
Notebook
The count of elements in the list is 2
10. WAP to store details of 5 students in following manner:
Anil Bhalothia
{101: {'name': 'Aseem', 'Phy': 89.0, 'Chem': 78.0, 'Maths': 95.0, 'CS': 97.0, 'Eng': 78.0},
102: {'name': 'Hardik', 'Phy': 87.0, 'Chem': 67.0, 'Maths': 96.0, 'CS': 80.0, 'Eng': 78.0},
103: {'name': 'Aditya', 'Acc': 99.0, 'Eco': 78.0, 'BSt': 97.0, 'Phe': 99.0, 'Eng': 56.0},

104: {'name': 'Hariom', 'Phy': 2.0, 'Chem': 1.0, 'Maths': 0.0, 'CS': 79.0, 'Eng': 10.0},
105: {'name': 'Sabu', 'Phy': 50.0, 'Chem': 60.0, 'Maths': 70.0, 'CS': 80.0, 'Eng': 90.0}}
a. WAP to find average marks scored by “sabu” in above dictionary.
b. WAP to find average marks scored in “phy” in above dictionary.
c. WAP to display name of “PCM” topper in above dictionary.
11. Use python dictionary to associate each open port to the service matched to it.
Your program should allow users to query if a port or service is in the dictionary
Allow users to add a new service and corresponding port, remove a service or change
the port number.
Implement your own logic and checks to get a running program. Your program should
display outputs like these below.

Figure 5-1: creating and displaying the dictionary of open ports

Figure 5-2: Samples of messages displayed when user queries - note: Python is case sensitive

12. Given the following:


os = ['Windows10', 'Debian', 'Ubuntu', 'Redhat']
portlist = {25:"SMTP",80:"HTTP",443:"HTTPS",23:"TELNET"}
Use the above and print the following:

13. A dictionary contains country name as key and city names as value in list form.
Anil Bhalothia
i.e. {“India”:[‘Agra’,’Bareilly’],’USA’:[‘NY’,’SF’]}. Now create another dictionary
which contains city name as key and their country as value. i.e. {‘Agra’:’India’,
’Bareilly’:’India’, ’NY’:’USA’, ’SF’:’USA’}.
14. WAP to accept name and section of n students of class XI and store in a
dictionary. Create another dictionary that contains all the sections as key and
student’s name as values.
15. WAP to accept name of n cities along with the state to which they belong.
Create another dictionary that contains state name as key and all the cities
belonging to that state as value.
16. Input a string and store its alphabets as key and frequency of alphabets as
value in dictionary and keys must be in ascending order.
If input is : MALAYALAM
Then output will be : {‘A’:4,’L’:2,’M’:2,’Y’:1}
17. A typical hospital has several specialties. Each specialty will have several wards
for in-patient. Each ward will have several beds.
a) Define a hospital dictionary with 2 hospitals. The expected output is shown below.

b) Add 2 specialties for hospital "AMK". The expected output is shown below.

c) Add 2 wards for "Heart Centre". The expected output is shown below.

d) Add 2 beds for "Ward-33". The expected output is shown below.

e) For each bed, add the patient-details

f) Print a nice report for the patients in Ward-33

You might also like