我在 edx.com 上找到了该课程的代码。有人能告诉我为什么我必须在 for 循环中使用余数吗?它如何影响字典?
def buildCoder(shift):
"""
Returns a dict that can apply a Caesar cipher to a letter.
The cipher is defined by the shift value. Ignores non-letter characters
like punctuation, numbers and spaces.
shift: 0 <= int < 26
returns: dict
"""
dict={}
upper = string.ascii_uppercase
lower = string.ascii_lowercase
for l in range(len(upper)):
dict[upper[l]] = upper[(l+shift)%len(upper)]
for l in range(len(lower)):
dict[lower[l]] = lower[(l+shift)%len(lower)]
return dict