For this assignment we needed to make a factorial calculator. The factorial of a number is the multiplication of all numbers that are lesser than that number until 0. For example the factorial of 4 is equal 4x3x2x1=24
This program required loops as we couldnt use the default python function from the math module.
-So first I used while loop so the user can use the program as many times he like.
res=”x”
while (str (res) != “n”):
print (“This program is a factorial calculator”)
n= int (input (“Please give me a positive integer number: “))
-Then I implemented a for loop in order to calculate the factorial of any given number.
for n in range (1,n+1):
num= num*n
print(“The factorial of the given number is: “,num)
print (“”)
print (“y= yes, n= no”)
res=str(input(“You wish to calculate another factorial of a number? “))
-And finally I used an If so my loop could work as I wanted.
if (res==”n”):
print(“”)
print(“Have a nice day!”)
else:
print(“”)
The final code:
The program:
Btw, I´m not sure if I completely understand how indentation works on python and on my Text editor.
#WSQ09 by alextenablog is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.