-2

I'm trying to write a python program that lets the user input the month by number for example the month of March as 3 and outputs the number of days and that mount

zimgold
  • 11
  • 1

1 Answers1

2

Is this a school project?

def get_days(month):
    days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    return days[(month-1) % 12]

I didn't consider a leap year since it wasn't mentioned,

but if you need it:

def get_days(month, leap=False):
    days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    return days[month-1] if not leap or month != 2 else 29
Joonyoung Park
  • 474
  • 3
  • 6