2016-04-02 24 views
-2

行18 我正在做一個文本漸變,似乎無法得到這個權利。這是我的代碼。 這裏的凹痕是什麼錯誤?'return'外部函數(使文本漸變)

import math 
gradient = ('FF24E9', 'F026EC', 'E128F0', 'D22AF3', 'C32CF7', 'A530FE', '8F3EFE', '7A4CFE', '655AFE', '5068FE', '3B76FE') 
def gradientmadness(text): 
    leng = len(text) 
output = '' 
if leng < 11: 
    for i in range(0, leng): 
     output += '<c=#%s>' % gradient[i] 
for i in range(0, leng): 
    output += text[i] + '</c>' 
else : 
    output += '<c=#' 
output += '><c=#'.join(gradient) 
output += '>' 
size = int(math.ceil(leng/11.0)) 
for i in range(1, 11 + 1): 
    output += text[(i - 1) * size: i * size] + '</c>' 
return output 
gradientmadness.command = "gradient1" 
+0

的格式很簡單,一旦你學會了它。將代碼粘貼到問題中;突出顯示它;按Ctrl-k。 Voila:代碼。 – zondo

+0

問題正是錯誤所說的:你在函數外有一個'return'。你如何解決它?這取決於你的目的。 – zondo

+0

在python中,縮進很重要。您的代碼編寫方式,'gradientmadness'只有1行代碼。 – tdelaney

回答

0

這裏是你的代碼正確的格式:

import math 


gradient = ('FF24E9', 'F026EC', 'E128F0', 'D22AF3', 'C32CF7', 'A530FE', '8F3EFE', '7A4CFE', '655AFE', '5068FE', '3B76FE') 
def gradientmadness(text): 
    leng = len(text) 
    output = '' 
    if leng < 11: 
     for i in range(0, leng): 
      output += '<c=#%s>' % gradient[i] 
     for i in range(0, leng): 
      output += text[i] + '</c>' 
    else : 
     output += '<c=#' 

    output += '><c=#'.join(gradient) 
    output += '>' 
    size = int(math.ceil(leng/11.0)) 

    for i in range(1, 11 + 1): 
     output += text[(i - 1) * size: i * size] + '</c>' 
    return output 


gradientmadness.command = "gradient1" 
+0

指出用戶做錯了什麼會很有幫助。 – tdelaney

+0

如果返回語句的縮進也是錯誤的,那麼在兩個內部的縮進是錯誤的。 – Randhawa