2016-07-25 532 views
-4

我似乎無法弄清楚這裏發生了什麼。當我編譯我得到的不符合錯誤。縮進錯誤:unindent不匹配任何外部縮進級別

它給了我關於縮進不匹配就行了誤差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;

另外:如果有人可以指出/向我解釋我的失敗,那就太好了。因爲我似乎無法在第二部分找到我的問題。這與第一個問題相同。

+2

沒有','在Python和縮進後'進行...:' – Julien

+0

@ JulienBernu實際上允許在其中使用分號 – 2016-07-25 05:47:09

+1

如果您使用的是Python 2,則可能會混合使用空格和製表符。這在Python 3中本身就是一個錯誤。你可能會嘗試使用'-t'標誌運行Python(這會使混合空白給出警告)或'-tt'(這會使其成爲錯誤)。 – Blckknght

回答

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; 
相關問題