首页 文章

缩进错误:unindent与任何外部缩进级别都不匹配

提问于
浏览
-4

我可以't seem to figure out what'在这里继续 . 当我编译时,我得到了不匹配的错误 .

它给出了关于 bgB = 0; 行上缩进不匹配的错误

def calcBG(ftemp):
"This calculates the color value for the background"
variance = ftemp - justRight;   # Calculate the variance
adj = calcColorAdj(variance);   # Scale it to 8 bit int
bgList = [0,0,0]                # initialize the color array
if(variance < 0):         
    bgR = 0;                    # too cold, no red         bgB = adj;                  # green and blue slide equally with adj         bgG = 255 - adj;     elif(variance == 0):            # perfect, all on green         bgR = 0;         bgB = 0;         bgG = 255;     elif(variance > 0):             # too hot - no blue
    bgB = 0;
    bgR = adj;                  # red and green slide equally with Adj
    bgG = 255 - adj;

所以在用@Downshift建议更新代码并添加一些elifs之后我得到了相同的东西 def calcBG(ftemp): "This calculates the color value for the background" variance = ftemp - justRight; # Calculate the variance adj = calcColorAdj(variance); # Scale it to 8 bit int bgList = [0,0,0] # initialize the color array if(variance < 0): bgR = 0; # too cold, no red bgB = adj; # green and blue slide equally with adj bgG = 255 - adj; elif(variance == 0): # perfect, all on green bgR = 0; bgB = 0; bgG = 255; elif(variance > 0): # too hot - no blue bgB = 0; bgR = adj; # red and green slide equally with Adj bgG = 255 - adj;

另外:如果有人可以向我指出/向我解释我的失败,那将是伟大的 . 因为我似乎无法在第二部分找到我的问题 . 这与第一个问题相同 .

1 回答

  • 0

    由于口译员告诉你压痕水平不一致 . 确保在第一行方法定义和 if 语句后缩进,除了修改缩进之外没有对代码进行任何更改:

    def calcBG(ftemp):
        """This calculates the color value for the background"""
        variance = ftemp - justRight;   # Calculate the variance
        adj = calcColorAdj(variance);   # Scale it to 8 bit int
        bgList = [0,0,0]                # initialize the color array
        if(variance < 0):         
            bgR = 0;                    # too cold, no red         bgB = adj;                  # green and blue slide equally with adj         bgG = 255 - adj;     elif(variance == 0):            # perfect, all on green         bgR = 0;         bgB = 0;         bgG = 255;     elif(variance > 0):             # too hot - no blue
            bgB = 0;
            bgR = adj;                  # red and green slide equally with Adj
            bgG = 255 - adj;
    

相关问题