How can this script be optimized?
def processor(n): """Finding the factorial of a given number. """ if n == 0 or n == 1: return 1 product = 1 for i in range(1, n + 1): product *= i return str(n) + '! = ' + str(product) def guardian(): """Asking for a number and guarding the script from raising an error. """ number = input('Number: ') if not number.isdecimal(): print('Please enter a positive integer number! \n') guardian() else: print(processor(int(number))) guardian()
- I'm new to factorials and have just understood the basic idea, so I'm sorry if I'm not precise.
- I'm a hobbyist and a beginner.