Read the question, write Python on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
Read a month number 1–12 and print how many days it has in a non-leap year.
February is 28. A match / case (or a small list) is cleaner than a long if-chain.
Input. One line: an integer 1–12.
Output. One integer: 28, 30, or 31.
Constraints
- 1 ≤ month ≤ 12
Examples
Input
2
Output
28
Input
4
Output
30
Input
1
Output
31
Hint
- Thirty days: 4, 6, 9, 11. February is 2. The rest are 31.
- days = [0,31,28,31,30,31,30,31,31,30,31,30,31]; print(days[month]).
Show correct code
Peek only after you have tried. You can still Check your own version.
month = int(input())
days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
print(days[month])
main.pyPython · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.