Question

In Python You must create a flowchart, and its corresponding Python program, to solve the following...

In Python

You must create a flowchart, and its corresponding Python program, to solve the following problem:

1. Using a repetition structure, evaluate the factorial of a positive whole number n:

n! = n · (n - 1) · (n - 2) · ... · 1, where n >=1

Your program must take into account the cases in which the user enters an incorrect number
and provide an error message for such cases.

Homework Answers

Answer #1
import sys
import math
print("Enter a whole number for factorial calculation :")
n = int(input()) # take user input int

def rec_factorial(n):
    if n == 0:
        return 1
    else:
        return n * rec_factorial(n-1) # recursive call
#CASE 1 : when n=0
if n < 0: 
    print("ERROR :: You have entered a negative value. Re-enter the value again !!!")
#CASE 2 : when n <0 (negative value)
elif n==0:
    print("ERROR :: You have entered zero. Re-enter the value again !!!")
#CASE 3 : when n>=1 (whole number)
else:
    print(rec_factorial(n))

Above is the python code getting the factorial of a whole number using recussion.

FLOWCHART :

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
You must create a flowchart, and its corresponding Python program, to solve the following problem: 1....
You must create a flowchart, and its corresponding Python program, to solve the following problem: 1. Using a repetition structure, evaluate the factorial of a positive whole number n: n! = n · (n - 1) · (n - 2) · ... · 1, where n >=1 Your program must take into account the cases in which the user enters an incorrect number and provide an error message for such cases.
C++ PROBLEM: Create a program that calculates the hyperfactorial of any positive integer n, where the...
C++ PROBLEM: Create a program that calculates the hyperfactorial of any positive integer n, where the hyperfactorial is equivalent to value obtained by the operation: 1^1*2^2*3^3*…..n^n . If user inputs the value that is not a positive value, display a message informing the user that the input is not valid and request a new input. Calculate the hyperfactorial first by creating a program that uses only nested “For loop” structure.
Write a program (also write its pseudocode and draw its flowchart) to prompt the user to...
Write a program (also write its pseudocode and draw its flowchart) to prompt the user to input the variables to solve the following problem: X2 + X×Y/Z – W*V3 Note 1: You should ask the user to input 5 number to be able to do this calculation. Note 2: You can use multiplication instead of power if you do not want to use it (as we have not officially covered it).
The following code to run as the described program on python. The extra test file isn't...
The following code to run as the described program on python. The extra test file isn't included here, assume it is a text file named "TXT" with a series of numbers for this purpose. In this lab you will need to take a test file Your program must include: Write a python program to open the test file provided. You will read in the numbers contained in the file and provide a total for the numbers as well as the...
Write a program display the following menu: Ohms Law Calculator 1. Calculate Resistance in Ohms 2....
Write a program display the following menu: Ohms Law Calculator 1. Calculate Resistance in Ohms 2. Calculate Current in Amps 3. Calculate Voltage in volts 4. Quit Enter your choice (1-4) If the user enters 1, the program should ask for voltage in Volts and the current in Amps. Use the following formula: R= E/i Where: E= voltage in volts I= current in amps R= resistance in ohms If the user enters 2 the program should ask for the voltage...
Using python, write the program below. Program Specifications: You are to write the source code and...
Using python, write the program below. Program Specifications: You are to write the source code and design tool for the following specification: A student enters an assignment score (as a floating-point value). The assignment score must be between 0 and 100. The program will enforce the domain of an assignment score. Once the score has been validated, the program will display the score followed by the appropriate letter grade (assume a 10-point grading scale). The score will be displayed as...
Python: Simple Banking Application Project Solution: • Input file: The program starts with reading in all...
Python: Simple Banking Application Project Solution: • Input file: The program starts with reading in all user information from a given input file. The input file contains information of a user in following order: username, first name, last name, password, account number and account balance. Information is separated with ‘|’. o username is a unique information, so no two users will have same username. Sample input file: Username eaglebank has password 123456, account number of BB12 and balance of $1000....
Create a flowgorithm program to calculate the Area of Circle first then do the Circumference of...
Create a flowgorithm program to calculate the Area of Circle first then do the Circumference of Circle. The user will have the ability to convert Area OR the Circumference. That means we need to add a decision structure to the program. Furthermore, they need to be able to do it as many times as they want. That means we need to add a main loop structure to the program. The user will also have the choice of whether to run...
In this programming exercise you will create an algorithm for solving the following version of the...
In this programming exercise you will create an algorithm for solving the following version of the m Smallest Numbers problem.   Instead of just returning the m smallest values as in homework 1, you want to return a list of the positions where the m smallest values are located without changing the original array. Your algorithm should meet the following specifications: mSmallest( L[1..n], m ) Pre: L is a list of distinct integer values. n is the number of elements in...
This is a Java program Program Description You work for a local cell phone company and...
This is a Java program Program Description You work for a local cell phone company and have been asked to write a program to calculate the price of a cell phone data plan being purchased by a customer. The program should do the following tasks: Display a menu of the data plans that are available to be purchased. Read in the user’s selection from the menu.  Input Validation: If the user enters an invalid option, the program should display an error...