"for" doubt in python

0

I'm starting to program with python language, and one of my exercises is to do the factorial number of a number n This is my code:

result=1
n=input("Deme un numero \n")
for i in range (1,n):
   result=result*i
print(result)

my question is how do I write the for range in the part of (1, n ) if 'n' is the number that I must reach or stop the for

    
asked by Mariosz124 10.10.2018 в 00:07
source

1 answer

0

Just like the comment says you have to change an by n + 1, since the for what it does is to do from 1 to n-1, when i is n, the code inside the loop is not executed anymore.

result=1
n=int(input("Deme un numero \n"))
for i in range (1,(n+1)):
   result=result*i
print(result)
    
answered by 10.10.2018 / 00:39
source