1.

create a dictionary whose keys are months names and whose values are number of days in the corresponding month

Answer»

d = {"January":31, "February":28, "March":31, "April":30, "May":31, "June":30, "July":31, "August":31, "September":30, "October":31, "November":30, "December":31}

a = input("Enter the name of the month: ")

for i in d.keys():

    if i==a:

        print("There are ",d[i],"days in ",a)

print()

print("Months arranged in alphabetical order: ", end="")

b=[]

for i in d.keys():

    b.append(i)

b.sort()

print(b)

print()

print("Months with 30 days: ", end="")

for i in d.keys():

    if d[i]==30:

        print(i, end="")

print()

print()

c = [("February",28)]

for i in d.keys():

    if d[i]==30:

        c.append((i,30))

for i in d.keys():

    if d[i]==31:

        c.append((i,31))

print(c)



Discussion

No Comment Found

Related InterviewSolutions