【发布时间】:2015-10-16 10:07:56
【问题描述】:
我有一个函数可以生成一个字符串列表,其中放置了 8 个字符串
def MajorScale(s):
i = notes.index(s)
t = i
major_scale = []
major_scale.append(notes[t])
t = t+2
if t >= 12:
t = t-12
major_scale.append(notes[t])
t = t+2
if t >= 12:
t = t-12
major_scale.append(notes[t])
t = t+1
if t >= 12:
t = t-12
major_scale.append(notes[t])
t = t+2
if t >= 12:
t = t-12
major_scale.append(notes[t])
t = t+2
if t >= 12:
t = t-12
major_scale.append(notes[t])
t = t+2
if t >= 12:
t = t-12
major_scale.append(notes[t])
t = t+1
if t >= 12:
t = t-12
major_scale.append(notes[t])
print(major_scale)
return major_scale
下一个函数调用 MajorScale 并依赖于 major_scale 列表来工作
def MajorChord(s):
MajorScale(s)
major_chord = []
major_chord.append(major_scale[0])
major_chord.append(major_scale[2])
major_chord.append(major_scale[4])
print(major_chord)
但是,当我运行程序时,我收到一条错误消息,提示“major_scale 未定义”
我只是不确定此时我做错了什么。如果有人能看到我犯的愚蠢错误,我很想知道。
【问题讨论】:
-
您使用了大写字母“M”。
-
在什么情况下?我有一个名为 MajorScale 的函数和一个名为 major_scale 的列表,但它们是不同的东西。