我想创建一个返回星期几的脚本,s
是代表星期几的字符串,并且
k
是一个整数,它返回K天后的星期几。
这是我的代码:
weekday = {
"Mon": 0,
"Tue": 1,
"Wed": 2,
"Thu": 3,
"Fri": 4,
"Sat": 5,
"Sun": 6
}
def wd(s, k):
s = list(weekday.values())[list(weekday.keys()).index(s)]
k %= 7
result = s + k
return result
print(wd('Sat', 23))
答案 0 :(得分:1)
尝试一下,
weekday = {
"Mon": 0,
"Tue": 1,
"Wed": 2,
"Thu": 3,
"Fri": 4,
"Sat": 5,
"Sun": 6
}
def wd(s, k):
s = list(weekday.values())[list(weekday.keys()).index(s)]
k %= 7
result = (s + k) % 7
return result
for key, value in weekday.items():
if value == wd('Sat', 1):
print(key)
答案 1 :(得分:1)
使用-- Example: part with "Brick red" BrickColor.
color = tostring(part.BrickColor)
print(string.format("%q", color))
> "Bright red"
模块:
calendar
输出:
import calendar
def wd(s, k):
return (dict(zip(list(calendar.day_abbr), range(7)))[s] + k % 7) % 7
print(wd('Sat', 23))
答案 2 :(得分:0)
您可以使用以下功能:
lst = list(weekday.keys())
def wd(s, k):
return lst[weekday[s] + k % 7]
print(wd('Mon', 1))
# Tue