Write a program that prompts the user to enter the month and year and displays the number of days in the month. For example, if the user entered month 2 and year 2000, the program should display that February 2000 has 29 days. If the user entered month 3 and year 2005, the program should display that March 2005 has 31 days. (Phyton)

Respuesta :

Answer:

from calendar import monthrange

year = input()

month = input()

print(monthrange(year, month)[1])

Explanation:

You don't need to download calendar from pip, it's integrated with Python if you are using Python 3x. Hope this helps!

Answer:

def MYD():

   from calendar import monthrange

   month = int(input('enter the month number between 1 and 12: '))

   if month >=13 or month <=0:

       print('pleas try again')

       return month

   year = int(input('enter what is the year: '))

   if month ==1:

       name = 'January'

   elif month ==2:

       name = 'February'

   elif month ==3:

       name = 'March'

   elif month == 4:

       name = 'April'

   elif month ==5:

       name = 'June'

   elif month ==6:

       name = 'June'

   elif month == 7:

       name = 'July'

   elif month ==8:

       name = 'August'

   elif month == 9:

       name = 'September'

   elif month ==10:

       name = 'October'

   elif month ==11:

       name = 'November'

   else:

       name = 'December'

   print('The', name,year,'has',monthrange(year, month)[1],'days')

MYD()

Explanation: