In this program, we will calculate the factorial of a number.
Steps to solve the program
- Take a number as input through the user.
- Create a variable and assign its value equal to 1.
- While the number is greater than 0 multiply the variable by given number and subtract 1 from the number.
- Print the output in the end.
num=int(input("Enter a number: "))
fact = 1
while num>0:
fact = fact*num
num = num-1
print(f"factorial of {num} is: ",fact)
Output :
Enter a number: 5
factorial of 5 is: 120