Home >Backend Development >Python Tutorial >How to write input month and output the number of days in the month using python
The calendar module can be used to calculate dates in Python.
The implementation code is as follows:
#!/usr/bin/python3 import calendar year = input("请输入年份:") month = input("请输入月份:") year = int(year) month = int(month) monthRange = calendar.monthrange(year,month) print("%d年%d月有%d天" % (year,month,monthRange[1]))
The effect is as follows:
For more Python related technical articles, please visit Python Tutorial column to learn!
The above is the detailed content of How to write input month and output the number of days in the month using python. For more information, please follow other related articles on the PHP Chinese website!