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

18th Oct 2016, 2:52 PM
Gabriel Leon Kristi
Gabriel Leon Kristi - avatar
6 Answers
+ 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)')
18th Oct 2016, 3:50 PM
Piyush Bhatia
Piyush Bhatia - avatar
+ 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="")
19th Oct 2016, 7:09 AM
Sunera
Sunera - avatar
+ 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
19th Oct 2016, 4:33 AM
Luke Armstrong
0
thanks, but I need output num! = .. x .. x .. = ..
19th Oct 2016, 1:14 AM
Gabriel Leon Kristi
Gabriel Leon Kristi - avatar
0
thanks, it works
19th Oct 2016, 9:02 AM
Gabriel Leon Kristi
Gabriel Leon Kristi - avatar
0
it's good practice to to import full modules, instead of certain functions
22nd Oct 2016, 2:00 AM
Alex Schrichte
Alex Schrichte - avatar