【发布时间】:2021-03-27 11:06:00
【问题描述】:
我正在尝试制作一个打印日历的程序,但它也没有打印我想要的内容。
假设打印:
Month
Sun Mon Tues Wed Thurs Fri Sat
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
而是打印:
Month
Sun Mon Tues Wed Thurs Fri Sat
for x in range(start-1)] + [str(x) for x in range(1,days+1)] + [ for x in range(start-1)] + [str(x) for x in range(1,days+1)] + [ for x in range(start-1)] + [str(x) for x in range(1,days+1)] + [ for x in range(start-1)] + [str(x) for x in range(1,days+1)] + [ for x in range(start-1)] + [str(x) for x in range(1,days+1)] + [
这就是我所拥有的,有人可以帮忙解决问题吗?
while (month != "January" and month != "February" and month != "March" and month != "April" and month != "May" and month != "June" and month != "July" and month != "August" and month != "September" and month != "October" and month != "November" and month != "December"):
print ("Thats not a correct response, please try again. ")
month = input("Enter the name of the month: ")
week = input("Enter the day of the week the month begins (1-7): ")
while (week != "1" and week != "2" and week != "3" and week != "4" and week != "5" and week != "6" and week != "7"):
print ("Thats not a correct response, please try again. ")
week = input("Enter the day of the week the month begins (1-7): ")
numDays = input("Enter the number of days in the month: ")
while (numDays != "28" and numDays != "29" and numDays != "30" and numDays != "31"):
print ("Thats not a correct response, please try again. ")
numDays = input("Enter the number of days in the month: ")
name = month
days = numDays
start = week
c = [" for x in range(start-1)] + [str(x) for x in range(1,days+1)] + [" for x in range(35-(days+start-1))]
print("{:^50s}".format(name))
print("\t".join(["Sun","Mon","Tues","Wed","Thurs","Fri","Sat"]))
for x in range(0,len(c),7):
print("\t".join(c[x:x+7]))
【问题讨论】:
-
如果这是一个直接的副本,那么您在声明
c时会遇到语法错误。有多余的双引号。 -
那我该如何解决
-
如何修复它首先取决于您到底想要什么(或您想要做什么)。你希望你的第一个列表理解 (
[" for x in range(start-1)]) 给你什么?c最终应该是什么?
标签: python string calendar integer typeerror