How to factor n! or

0

How to factor a number?

n! or! n

Example:

Let's take x = 5

 x = input('Digite um número inteiro: ')
 i = 1
 while i <= x:
      for i in range(x):
        i = i + 1
        a = []
        a.append(i)
        print(a)
      break

The result should be 120, however the interpreter prints this:

[1]
[2]
[3]
[4]
[5]

With 'append' I was able to print 'i' from 1 to 'x'. In the example above, 'i = 1' and 'x = 5'. What I can not do is multiply 'i' from 1 to 'x'!

    
asked by anonymous 08.07.2017 / 21:38

1 answer

0

You're making things too complicated:

x = 5
total = 1
for n in range(x):
    total = total * (n + 1)


print(total)
    
11.07.2017 / 17:33