Dictionaries || Type C || Sumita Arora || Class 11 || Computer science || Solution



Q1. Write a program to enter names of employees and their salaries as input and store them in a dictionary.


Q2. Write a program to count the number of times a character appears in a given string.


Q3. Write a program to convert a number entered by the user into its corresponding number in words.


Q4. 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 list 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 dictionary, create a list whose entries are the number of wins of each team.
(c) Using the dictionary, create a list of all those teams that have winning records.



Q5. Write a program that repeatedly asks the user to enter product names and prices. Store all of these in a dictionary whose keys are the product names and whose values are the prices.When the user is done entering products and price, allow them  to repeatedly enter a product name and print the corresponding price or a message if the product is not in the dictionary.


Q6. Create a dictionary whose keys are month names and whose values are  number of days  in the corresponding months.
(a) Ask the user to enter the month name and use the dictionary to tell how many days are in the month.
(b) Print out all of the keys in alphabetical order.
(c) Print out all of the month with 31 days.(d) Print out the (key-value) pairs sorted by the number of the days in each month.



Q7. Can you store the details of 10 students in a dictionary at the same time?
details include – rollno, name, marks, grade etc. Give example to support your answer.



Q8. Given the dictionary x = {‘k1’: ‘v1’, ‘k2’ : ‘v2’, ‘k3’ : ‘v3’},create a dictionary with the opposite mapping, write a program to create the dictionary.


Q9. Given two dictionaries say D1 and D2. Write a program that lists the overlapping keys of the two dictionaries, i.e., if a key of D1 is also a key of D2, the list it.


Q10. Write a program that checks if two same values in a dictionary have different keys.


Q11. Write a program to check if a dictionary is contained in another dictionary.


Q12. A dictionary D1 has values in the form of lists of numbers. Write a program to create a new dictionary D2 having same keys as D1 but values as the sum of the list elements.



4 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post