Professional Documents
Culture Documents
Assignment 9 PDF
Assignment 9 PDF
START
Set loop = 1
While loop = 1:
define recursion(x)
If x == 1:
return 1
else:
return (x * recursion(x 1))
print message
num = int(input())
if num >= 1:
Print recursion(num)
Prompt user for another num to factorialize
if yes :
loop = 1
else:
loop = 0
else:
Prompt user for a non-negative integer
endwhile
END
START
loop = 1
YES
While loop == 1
Define recursive(x)
If x == 1
NO
YES
NO
recursive = 1
num = int(input())
If num >= 1
NO
YES
Call recursion(num)
END
NO
If answer = Y , y , Yes ,
YES , yes
Python Code:
# Let's Factorialize!
loop = 1
while loop == 1:
# Recursive function for factorialization
def recursion(x):
if x == 1:
return 1
else:
return(x * recursion(x - 1))
print("Let's Factorialize")
num = int(input("Enter a non-negative integer: "))
if num >= 1:
print("The factorial of", num, "is", recursion(num))
print()
answer = input("Would you like to find the factorial of another non-negative integer? Y/N: ")
print()
# Error checking user input for continuation of the factorial program
if answer in ("Y", "y", "YES", "Yes", "yes"):
loop = 1
else:
loop = 0
# Error checking user input for initial input variable >0
else:
print("You did not enter a non-negative integer. Please try again.")
YES