[Type C]Q9. Create a dictionary whose keys are month names and whose values are the number of days in the corresponding months.

Program code:

Clear Doubts with Computer Tutor
In case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in


Enter a month:June
Number of days in June is 30 
All months in sorted order are as follows: 
['April', 'August', 'December',
 'February','January', 'July',
 'June', 'March', 'May',
 'November', 'October', 'September'] 
Month having 31 day is: January 
Month having 31 day is: March 
Month having 31 day is: May 
Month having 31 day is: July 
Month having 31 day is: August 
Month having 31 day is: December 
Key,value pairs in sorted order are: 
[('February', 28), ('April', 30), ('June', 30), ('November', 30), 
('October', 30), 
('September', 30), ('August', 31), 
('December', 31), ('January', 31),
('July', 31), ('March', 31), 
('May', 31)]

A dictionary is a collection that is unordered, changeable, and indexed. In Python, dictionaries are written with curly brackets, and they have keys and values.

You can access the items of a dictionary by referring to its key name, inside square brackets.

Dictionaries are optimized to retrieve values when the key is known.

Basic python functionality is demonstrated in above program.

To view all the lessons in chapter 1: http://computertutor.in/class-12-computer-science/chapter-2/

To view entire class 12 computer science study material: http://computertutor.in/resources/

You cannot copy content of this page