<python 3.>先前运行else语句时,无法在if-else循环中返回函数

So I couldn't return keygen(n) if I type in n=0 or n<0. However, it could call keygen(n) if my first entry is >0 .

请帮忙

import random
import string
import base64

def keygen(n):

    end_string=''

    for i in range(n-1):
     alpha = random.choice(string.ascii_letters)
     end_string += alpha


    b64_string=base64.b64encode(bytes(end_string,'utf-8'))
    return b64_string 



def main():

    n=int(input('\nnumber of iterations\n'))

    if n > 0:
       return keygen(n)

    else:
       print('\nplease type in non-zero value!!\n')
       return main()