Answer:
Python code along with step by step comments is provided below.
Python Code with Explanation:
# get input from the user
num = int(input("Enter a number: "))
factorial = 1
# check if the number is within the allowed range
if num>=0 and num<=30:
# if number is within the range then run a for loop
for i in range(1,num + 1):
# this is how a factorial is calculated
factorial = factorial*i
# now check if the result is withing the limit or not
if factorial>2147483647:
# if result is not within the limit then terminate the program
print("Sorry, cant handle the result")
exit()
# if result is within the limit then print the result
print("The factorial of",num,"is",factorial)
else:
# if input is not withing the range then print wrong input
print("Sorry, Wrong input")
Output Results:
Enter a number: 10
The factorial of 10 is 3628800
Enter a number: 15
Sorry, cant handle the result
Enter a number: 35
Sorry, Wrong input