Python Exercise: Convert month name to a number of days
Python Conditional: Exercise - 33 with Solution
Write a Python program to convert month name to a number of days.
print("List of months: January, February, March, April, May, June, July, August, September, October, November, December") month_name = input("Input the name of Month: ") if month_name == "February": print("No. of days: 28/29 days") elif month_name in ("April", "June", "September", "November"): print("No. of days: 30 days") elif month_name in ("January", "March", "May", "July", "August", "October", "December"): print("No. of days: 31 day") else: print("Wrong month name")
List of months: January, February, March, April, May, June, July, August, September, October, November, Decemb er Input the name of Month: April No. of days: 30 days
Visualize Python code execution:
The following tool visualize what the computer is doing step-by-step as it executes the said program:
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to check whether an alphabet is a vowel or consonant.
Next: Write a Python program to sum of two given integers. However, if the sum is between 15 to 20 it will return 20.
What is the difficulty level of this exercise?
Test your Python skills with w3resource's quiz
Python: Tips of the Day
Returns a list with n elements removed from the beginning
def tips_take(itr, n = 1): return itr[:n] print(tips_take([1, 2, 3], 5)) print(tips_take([1, 2, 3], 0))
[1, 2, 3] 
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework