Last answered:

11 Apr 2020

Posted on:

11 Apr 2020

0

Factorial

Hello,
Could someone, please, have a look at the code and tell me why it does not execute the commands (when I type in a number, e.g. 5, it just prints it and that's all)?
I am a beginner and after having checked all I know, I am not able to see the error.

I would appreciate.

n = input('Please, give a number. Type exit to leave. \n>>> ')

while n.lower() != 'exit':
while not n.isdigit():
print('A digit bigger than zero, please!')
n = input('Here: \n>>> ')

fact = 1
for i in range(1, n+1):
fact = fact*i

print(f'The factorial of {n} equals {fact}.')


 

1 answers ( 0 marked as helpful)
Posted on:

11 Apr 2020

0
This will work!   n = int(input("Enter the number: "))
if(n>0):
         fact = 1
         for i in range(1, n+1):
                 fact = fact*i
         print("The factorial of " + str(n) + " is " + str(fact))
else:
         print("Please Enter positive integers")

Submit an answer