我想创建一个机器人,它将向我显示两种不同类型的周(分子和分母)的时间表,因为我们在不同的星期有不同的课程。下面是我的代码的一小部分:
from datetime import datetime, date
def what_week_now():
my_date = datetime(2020, 3, 16) # the year, month, day of the reference week
days = (datetime.now() - my_date).days # difference in days
days -= days % 7 # align on monday
if days % 14 == 0:
return 1 # numerator week
else:
return 0 # denominator week
# determining the day of the week for today, as an example
if date.today().weekday() == 0:
print("Monday lesson list")
if date.today().weekday() == 1:
print("Tuesday lesson list")主要问题是如何使用此函数为一周创建两种不同类型的课程列表(例如,分子周的周一课程列表1和分母周的周一课程列表2)?
发布于 2020-03-16 20:23:41
只需在另一个嵌套的if中调用该函数,如下所示:
if date.today().weekday() == 0:
if what_week_now() == 0:
print("Monday lesson list denominator")
else:
print("Monday lesson list enumerator")
if date.today().weekday() == 1:
if what_week_now() == 0:
print("Tuesday lesson list denominator")
else:
print("Tuesday lesson list enumerator")另一种选择是这样做:
if what_week_now() == 0:
if date.today().weekday() == 0:
print("Monday lesson list denominator")
if date.today().weekday() == 1:
print("Tuesday lesson list denominator")
else:
if date.today().weekday() == 0:
print("Monday lesson list enumerator")
if date.today().weekday() == 1:
print("Tuesday lesson list enumerator")https://stackoverflow.com/questions/60705917
复制相似问题