In this python basic program, we will get the factorial of the given number using while loop.
Steps to solve the program
- Take a number as input through the user and create a variable named fact and assign its value equal to 1.
- While the input number is greater than 0 multiply the fact by the number.
- After each multiplication subtract 1 from the input number.
- Print the output,
num = n = int(input("Enter a number: "))
fact = 1
while n > 0:
fact *= n
n -= 1
print(f"Factorial of {num}: {fact}")
Output :
Enter a number: 5
Factorial of 5: 120
calculate days between 2 dates.
reverse a given number.