【发布时间】:2022-11-28 01:54:50
【问题描述】:
我正在做这个项目,它几乎完成了,但是从 5 月开始,日期排错了星期几。我不确定如何修复计数。按照我的设置方式,2 月计数为 7,这会导致 3 月出现问题,并导致 3 月打印完全错误。我添加了一个简单的修复程序,但这会导致 5 月在错误的日期开始,其余月份也会如此。我相信这是一个快速解决方案,只是想让另一双眼睛关注我的工作。
month_header = 'Su\tM\tTu\tW\tTh\tF\tSa'
months = { 'January':31, 'February':28, 'March':31, 'April':30, 'May':31,
'June':30, 'July':31, 'August':31, 'September':30, 'October':31,
'November':30, 'December':31 }
# k is the key (month name), v is the value (month length in days)
month_daycount = 0
for k,v in months.items():
print(k) # print the month name
print(month_header)
while month_daycount > 7:
month_daycount -= 7
feb_bug = 0
if month_daycount == 7:
month_daycount = 3
feb_bug = 1
#Fixes the Feb issue^
count = month_daycount
for i in range(1, v+1):
tabs = ''
while month_daycount > 0:
tabs += '\t'
month_daycount -= 1
print(tabs, i, end='\t')
#this end will finish the parameter with whatever is in quotations
count += 1
if count == 7:
print("\n")
count = 0
month_daycount = v
if feb_bug == 1:
month_daycount += 3
feb_bug = 0
# TODO: when you begin a new month, indent it the right number of spaces
print('\n')
【问题讨论】:
标签: python dictionary count