Answer to Question #183775 in Python for Shehry

Question #183775

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

  

 



1
Expert's answer
2021-04-20T15:22:10-0400
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()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS