0

How do I calculate the factorial of a number in a program in Python 3?

I need help creating a program that calculates the factorial of a number, I think I have the concept down but I need help with the rest. x = input(int('Input a number that you would like the factorial of \n')) while x > 1: x = x * (x - 1) print(x)

17th Jan 2018, 7:52 PM
Aidan Tilgner
Aidan Tilgner - avatar
2 Answers
0
n = input("Enter the number") for i in range(n) x = x * i print(x)
17th Jan 2018, 9:07 PM
Krishnatheja Vanka
Krishnatheja Vanka - avatar
0
If you do that, x will never be <= 1. So, set other variable that works like the number you will multiply. n = input(int("bla")) x = 1 while n > 1: x *= n n -= 1 print(x) # x *= n its the same like x = x * n
18th Jan 2018, 2:35 AM
SebastiĂĄn Zapata
SebastiĂĄn Zapata - avatar