如何在功能结束时显示输入

时间:2018-12-13 21:38:19

标签: python python-3.x

在主功能内的代码末尾,我询问用户是否要重试,但是在执行程序时不会显示。这是我的代码

def get_factor_count(num):
    list = []
    for i in range(1, num + 1):
            if num % i == 0:
                list.append(num)      
    print(num, "has", len(list), "factors")

def main():
    num = int(input('\nPlease enter a number: '))
    while num < 1:
        print('NUMBER MUST BE GREATER THAN 1! Please try again.')
        num = int(input('\nPlease enter a number: '))
    if num > 1:
        for i in range(2, num):
            if (num % i) == 0:
                print(num, "IS NOT A PRIME NUMBER")

            else:
                print(num, "IS A PRIME NUMBER")
            return get_factor_count(num)

    again = input('Try again? (Y/N): ')
    while again.upper() == 'Y':
        num = int(input('\nPlease enter a number: '))
        main()
        if again.upper() == 'N':
            print('Goodbye')

main()

0 个答案:

没有答案