Question

In: Computer Science

Design a program that asks the user for a number and the program computes the factorial...

Design a program that asks the user for a number and the program computes the factorial of that number and displays the result .


Implement with two different modules - one that uses a for loop and one that uses a while loop






Grading Rubrick


Program Compiles Cleanly  syntax errors25 pts-5 per errorProgram runs without runtime errors ( validation)run-time errors 25 pts-5 per errorProgram give correct answersLogic errors30 pts-5 per errorProgram is repeatableNot repeatable5 pts-5 ptsProgram is well modularizedBarely Modularized10 pts- 5 ptsDocumented WellDocumented Some5 pts- 3 ptsSomething Cool (but relevant) beyond strict requirementsSomething extra5 pts + 3 ptsBest possible grade : 105

Solutions

Expert Solution

The program is designed using Python Programming Language.

The code with use of WHILE LOOP is as follows:

user_input=int(input("Enter your input: "))      #To take an integer value as the user input and store it in user_input variable
factorial=1                                                        #To initialize the value of variable factorial to 1
i=1                                                                    #To initialize the value of i to 1
while i<=user_input:                                        #To execute while loop as long as the condition "i<user_input" is true                           
    factorial=factorial*i                                      #The factorial variable gets stored by "factorial*i" value as long as the while loop condition is true
    i=i+1                                                            #And with the increment in the value of i
print("Factorial of ",user_input,"=",factorial)   #The print statement to display the factorial of the taken user input                                                                             

The code with use of FOR LOOP is as follows:

user_input = int(input("Enter your input: "))      #To take an integer value as the user input and store it in "user_input" variable
factorial = 1                                                        #To initialize the value of variable factorial to 1
for i in range(1, user_input + 1):                       #For loop is executed with i in range of 1 and user_input with default increment of i with 1
    factorial = factorial * i                                     #The factorial variable gets stored by "factorial*i" value as long as the for loop condition is true
print("Factorial of ", user_input, "= ", factorial)  #The print statement to display the factorial of the taken user input     


Related Solutions

Write a program that asks the user to enter 3 grades and computes the minimum and...
Write a program that asks the user to enter 3 grades and computes the minimum and the maximum of those 3 grades and prints it. Hint: Use the Math.min() and Math.max() methods. This program will compute the smallest and highest of 3 grades entered by the user. Enter 3 grades separated by a space: 100 85.3 90.5 Smallest: 85.3 Highest: 100.0 Bye
Create a program that asks the user to input three numbers and computes their sum. This...
Create a program that asks the user to input three numbers and computes their sum. This sounds simple, but there's a constraint. You should only use two variables and use combined statements. You can use the output below as a guide. Please enter the first number: 4 Please enter the second number: 2 Please enter the third number: 9 The sum of the three numbers is: 15.
java programing project Implement a program that computes the Fibonacci of a specified number, the factorial...
java programing project Implement a program that computes the Fibonacci of a specified number, the factorial of a specified number, or estimates the value of 'e' using the specified number of iterations (of a Taylor series). Please feel free to use the Internet to find resources that explain how to estimate the value of 'e' using a Taylor series. In the case of no or invalid number of parameters, the program should show help instructions that looks like: --- Assign...
1. Write a program in C++ to find the factorial of a number. Prompt the user...
1. Write a program in C++ to find the factorial of a number. Prompt the user for a number and compute the factorial by using the following expression. Use for loops to write your solution code. Factorial of n = n! = 1×2×3×...×n; where n is the user input. Sample Output: Find the factorial of a number: ------------------------------------ Input a number to find the factorial: 5 The factorial of the given number is: 120 2. Code problem 1 using While...
Write a program IN JAVA that asks the user for a number. The program should check...
Write a program IN JAVA that asks the user for a number. The program should check the number to ensure that it is valid (if not, the user should enter a valid number to continue.) The program should print out all of the prime numbers from 2 up to the number, with up to 10 numbers per line. (Recall: A prime number is a number that is only divisible by itself and 1.) The code should ask the user if...
Write a program that asks the user to enter an unsigned number and read it. Then...
Write a program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6. COMMENT COMPLETE CODE PLEASE
Develop a program that asks a user to enter the number 10, and then it outputs...
Develop a program that asks a user to enter the number 10, and then it outputs COUNT-DOWN from 10 to 0. using for-loop
Develop a program that asks a user to enter the number 10, and then it outputs...
Develop a program that asks a user to enter the number 10, and then it outputs COUNT-DOWN from 10 to 0.
Write a design algorithm and a python program which asks the user for the length of...
Write a design algorithm and a python program which asks the user for the length of the three sides of two triangles. It should compute the perimeter of the two triangles and display it. It should also display which triangle has the greater perimeter. If both have the same perimeter it should display that the perimeters are the same. Formula: Perimeter of triangleA = (side1A + side2A +side3A) See the 2 sample outputs. Enter side1 of TriangleA: 2 Enter side2...
Design a complete program that asks the user to enter a series of 20 numbers. The...
Design a complete program that asks the user to enter a series of 20 numbers. The program should store the numbers in an array and then display each of the following data: I. The lowest number in the array II. The highest number in the array III. The total of the numbers in the array IV. The average of the numbers in the array *PYTHON NOT PSUEDOCODE AND FLOW CHART!!!!*
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT