'返回'外部功能(制作文字渐变)

时间:2016-04-02 00:24:59

标签: python

第18行 我正在制作文字渐变,似乎无法做到这一点。这是我的代码。 这里的缩进是什么错误的?

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"

1 个答案:

答案 0 :(得分: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"