0
how to make program when user input 3 output : 3! = 1 x 2 x 3 = 6
please help me how to make program when user input number can display output like this ex = 10 output : 10! = 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 = 3628800 thanks
6 Respostas
+ 2
# hope this helps
num = int(input('Please enter the number whose factorial is required : '))
count = 1
fact = 1
while count <= num :
fact = fact * count
count += 1
print('The factorial of the given number is : + str(fact)')
+ 2
you can use math.factorial() to calculate factorial easily
here is my solution
it will print the output exactly as you want
(python 3)
from math import factorial as f
n=int(input("Enter the number to check Factorial : "))
x=list(map(str,list(range(1,n+1))))
print(n,"! = "," x ".join(x)," = ",f(n),sep="")
+ 1
num = int(input('input an int: \n'))
def fact(x):
if x < 2:
print("1 = ", end=" ")
return 1
else:
print('{} * '.format(x), end=' ')
return x * fact(x - 1)
print('{}! = '.format(num), end=' ')
print(fact(num))
this works, but in backwards order.
5! = 5 * 4 * 3 * 2 * 1 = 120
0
thanks, but I need output
num! = .. x .. x .. = ..
0
thanks, it works
0
it's good practice to to import full modules, instead of certain functions