Programming Examples

Python program to create a dictionary whose keys are month names and values are their corresponding number of days


WAP to create a dictionary named year whose keys are month names and values are their corresponding number of days.

Solution

dict={}
ch='y'
while ch=='y' or ch=='Y':
    month=input("Enter name of month : ")
    days=eval(input("Enter no. of days of month : "))
    dict[month]=days
    ch=input("Want to add more months (Y/N) : ")
print(dict)
Output/ Explanation:

Enter name of month : january
ENter no. of days of month : 31
Want to add more months (Y/N) : y
Enter name of month : February
ENter no. of days of month : 28
Want to add more months (Y/N) : n
{'january': 31, 'February': 28}
Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad