Write a program factorial.py that accepts an integer from the user and displays its factorial.
Using your program evaluate the factorials of the integers from 1 - 5 and print the results. Sample output is as follows:
X Factorial of X
5 120
def main():
integerValue = eval(input("Enter a integer value from 1-5: "))
fact=calculateFctorial(integerValue)
print(f"The factorial of {integerValue} is {fact}")
print("X\t\tFactorial of X")
print(f"{integerValue}\t\t{fact}")
def calculateFctorial(integerValue):
fact = 1
for factor in range(integerValue,1,-1):
fact = fact * factor
return fact
main()
Comments
Leave a comment