在主功能内的代码末尾,我询问用户是否要重试,但是在执行程序时不会显示。这是我的代码
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()