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'))