204

版权声明:根号v587版权所有 https://blog.csdn.net/hcmdghv587/article/details/82594771
strList = [chr(i) for i in range(65, 65+26)]
strList += [chr(i) for i in range(97, 97+26)]
def strrange(*args):
    def valid(arg):
        return len(arg) == 1 and arg.isalpha()
    if len(args) == 1:
        if not valid(args[0]):
            raise Exception("参数错误!")
        else:
            temp = ''.join(strList[:strList.index(args[0])])
            return temp
    elif len(args) in (2, 3):
        if len(args) == 3:
            step = args[2]
        else:
            step = 1
        if not valid(args[0]) or not valid(args[1]):
            raise Exception("参数错误!")
        else:
            temp = ''.join(strList[strList.index(args[0]):strList.index(args[1]):step])
            return temp
print(strrange('z'))
print(strrange('e'))
print(strrange('Z', 'g'))
print(strrange('A', 'Z', 3))
print(strrange('m', 'M', -5))
print(strrange('m', 'M'))

猜你喜欢

转载自blog.csdn.net/hcmdghv587/article/details/82594771
204