我希望有人能给我一些返回日历数据的方法的例子,这些日历数据可以做以下事情。
示例:
输入(‘:') -2018年输入
input('Month:') - 7
最终结果:2018年7月的工作日数为(22)。
示例:
输入(‘:') -2018年输入
input('Month:') - 7
input('date:') - 20
最终结果: (20)是一个(星期五),是(15) weekday of (7月),(2018)。
这是我到目前为止所能创建的代码...
import calendar
year = float(input('Year: '))
month = float(input('Month: '))
input_year = []
input_month = []
if year >= 1000 and year <=3000:
input_year.append(year)
if month >= 1 and month <=12:
input_month.append(month)
cal_format = calendar.TextCalendar(calendar.MONDAY)
result_cal = cal_format.formatmonth(int(input_year[0]), int(input_month[0]))
print(result_cal)
THE END RESULT IS...
Year: 1978
Month: 3
March 1978
Mo Tu We Th Fr Sa Su
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
这只会用Sat打印出文本日历。和Sun,所以我至少可以在视觉上把它们排除在外。但我真的希望能够以编程方式排除它们,并能够输入上述变量来计算一个月中的周日,以及该月内的每一天是哪一周。
https://stackoverflow.com/questions/51446944
复制相似问题