assignment 9
DESCRIPTION
Assignment 9TRANSCRIPT
START
loop = 1
While loop == 1 Define recursive(x) If x == 1 recursive = x * (recursive(x – 1))
recursive = 1
Print Let s Factorialize!
num = int(input())
Print Enter a non-negative integer:
If num >= 1Print You did not enter a non-negative integer
Call recursion(num)
Print The factorial of num is recursion(num)
Print Would you like to find the factorial of another number?
If answer = Y , y , Yes , YES , yes
answer = input
END
YES
NOYES
YES
YESNO
NO
NO
Pseudocode: STARTSet loop = 1While 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 integerendwhileEND
Python Code:
# Let's Factorialize!
loop = 1while 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.")