第1个回答 2018-07-09
def formatit(x): if isinstance(x,int): x=str(x) return (' '+x)[-2:]def main(): title=['S','M','T','W','Th','F','S'] days=eval(input('Enter number of days:')) firstday=input('The first day of the week:') fd=title.index(firstday) wts=[] wt=['','','','','','',''] #一个星期的模板 for i in range(days): wt[(i+fd)%7]=i+1 if (i+fd)%7==6: #如果满一个星期,append当前模板,换新模板 wts.append(wt) wt=['','','','','','',''] if (i+fd)%7!=6: #如果最后一天不是星期六,append当前板 wts.append(wt) print(' '.join(map(formatit,title))) #按预想的格式输出标题 for x in wts: print(' '.join(map(formatit,x))) #按预想的格式输出星期main()