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

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...
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!!!!*
2. Write a program C++ that asks the user for a number (not necessary to force...
2. Write a program C++ that asks the user for a number (not necessary to force any particular requirements). Write a function with the following signature: double square(double x) that returns the square of the user's number (x * x). 3. Write a C++ program that asks the user for an integer. Write a function that returns 1 of the number is even, and 0 if the number is odd. Use this function signature: int isEven(int x). 4. Write a...
Write a java program that asks the user for a number n and gives them the...
Write a java program that asks the user for a number n and gives them the possibility to choose between computing the sum and computing the product of 1,…,n. Example of running this program: Enter an integer number n: __7________ Enter Sum or Product: __Sum__________________________________ Program output: Sum of 1 ... 7 Sum or Product: Sum Sum = 28 Now second sample of second execution Enter an integer number n: __5__________________________________ Enter Sum or Product: __Product__________________________________ Program output:  Product of 1...
write a program that: 1) asks the user to enter grades, a negative number is the...
write a program that: 1) asks the user to enter grades, a negative number is the signal to stop entering. (while loop) - add each grade to a list (do not add the negative number to the list) after the while loop to enter grades is finished: 2) use a for loop on the list to calculate the average of all numbers in the list 3) use a for loop on the list to find the largest number in the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT