Question

In: Computer Science

Write a Python program that: Create the algorithm in both flowchart and pseudocode forms for the...

Write a Python program that:

  1. Create the algorithm in both flowchart and pseudocode forms for the following requirements:
  2. Reads in a series of positive integers,  one number at a time;  and
  3. Calculate the product (multiplication) of all the integers less than 25,  and
  4. Calculate the sum (addition) of all the integers greater than or equal to 25.
  5. Use 0 as a sentinel value, which stops the input loop. [ If the input is 0 that means the end of the input list. ]
  6. After all the data is entered, then display the resulting sum and product values with labels.   ** Added **
  7. Once you completed the algorithm, then code the program in Python.
  8. 2 forms of the algorithm, plus the python source (*.py file listing) and a screenshot of the running program.

Hint: For each input number - if the number is < 25  then multiply it times the overall product, else if it is >= 25 then add it to the overall sum. Be sure to initialize the product and sum it to appropriate initial values.

Solutions

Expert Solution

Ok, I will give the answer completely,

python program(I had included comments for better understanding, also please refer the screenshot of the code, attached below , of you are having trouble in understanding the indentation)

# Initialize product and sum initial values
productResult = 1
sumResult = 0 

# read the inputs from the user
while True:
  n = int(input("Enter a positive integer, 0 to quit : "))
  if n<0:
    print("Invalid value, enter positive integer")
    continue
  if n ==0:
    break
  if n < 25:
    productResult = productResult * n
  else:
    sumResult = sumResult + n
# Now the program is out of the loop, display the results
print(f"The resultant sum : {sumResult}")
print(f"The resultant product : {productResult}")

Screenshot of the code :

Screenshot of the output :

Algorithm :

STEP 1  : INITIALIZE THE VARIABLE productResult AS 1
STEP 2  : INITIALIZE THE VARIABLE sumResult AS 0
STEP 3  : READ N
STEP 4  : REPEAT UNTIL N NOT EQUAL TO 0
STEP 5  :       IF N < 0
STEP 6  :         THEN, PRINT "Invalid value, enter positive integer" AND GO THE STEP 4
STEP 7  :       IF N < 25
STEP 8  :         THEN, SET : productResult = productResult * n
STEP 9  :       IF N>=25
STEP 10 :         THEN, SET : sumResult = sumResult + n
STEP 11 :       READ N
STEP 12 : PRINT "The resultant sum :",sumResult
STEP 13 : PRINT "The resultant product :",productResult

FLOWCHART :


Related Solutions

Homework Arrays and Tables In this assignment you are to create an algorithm, flowchart, and pseudocode...
Homework Arrays and Tables In this assignment you are to create an algorithm, flowchart, and pseudocode for a solution of the following problem. This solution will include the use of arrays needed to complete all parts of the logic. You have requested to develop a program that will record and process the rainfall totals of a 12 month period. You would use an array to store each months total. Once all 12 months amounts are entered then your solution need...
create flowchart using Flowgorithm and Pseudocode for the following program example:   Design a program for Jones...
create flowchart using Flowgorithm and Pseudocode for the following program example:   Design a program for Jones College. The current tuition is $12,000 per year, and tuition is expected to increase by 5 percent each year. Display the tuition amount for each year over the next five years (use a looping structure).
DESIGN A FLOWCHART IN FLOWGORITHM AND WRITE THE PSEUDOCODE Number Analysis Program Design a program that...
DESIGN A FLOWCHART IN FLOWGORITHM AND WRITE THE PSEUDOCODE Number Analysis Program Design a program that asks the user to enter a series of 20 numbers. The program should store the numbers in an array and then display the following data: The lowest number in the array. The highest number in the array. The total of the numbers in the array. The average of the numbers in the array. PLEASE AND THANK YOU
Write an algorithm (flowchart OR Pseudocode) for the following problem Take input character from the user...
Write an algorithm (flowchart OR Pseudocode) for the following problem Take input character from the user unless he enters '$'. Thereafter display how may vowels were entered by the user. Also display the number of each vowel ('a', 'e', 'i', 'o' and 'u') separately. For example if the user enters B a b e c o o d i u g o a l $ Then we have the output below: #A=2 #E=1 #I=1 #O=3 #U=2
Write an algorithm (flowchart OR Pseudocode) for the following problems: Take ten different numbers as input...
Write an algorithm (flowchart OR Pseudocode) for the following problems: Take ten different numbers as input and display the sum of there squares (SS). Example: let the inputs are: 3, 0, -1, 0, 9, -5, 6, 0, 2, 1 then 157 is displayed, because: SS=32+02+(-1)2+02+92+(-5)2+62+02+22+12=157 Take input character from the user unless he enters '$'. Thereafter display how may vowels were entered by the user. Also display the number of each vowel ('a', 'e', 'i', 'o' and 'u') separately. For...
For this problem you should describe the algorithm using a flowchart and then write Python code...
For this problem you should describe the algorithm using a flowchart and then write Python code to implement the algorithm. You are to create a Python program file for your code. Include in your HW document a photo of your flowchart and a screenshot of your program file and the output in IDLE that results when you run the program. The algorithm: Ask the user to input their annual salary and then calculate and print the weekly salary (annual/52). I...
6. Write a program in C programming (compile and run), a pseudocode, and draw a flowchart...
6. Write a program in C programming (compile and run), a pseudocode, and draw a flowchart for each of the following problems: a) Obtain three numbers from the keyboard, compute their product and display the result. b) Obtain two numbers from the keyboard, and determine and display which (if either) is the smaller of the two numbers. c) Obtain a series of positive numbers from the keyboard, and determine and display their average (with 4 decimal points). Assume that the...
Write an algorithm and draw a flowchart for the following problem: Create an adaptive cruise control...
Write an algorithm and draw a flowchart for the following problem: Create an adaptive cruise control for a car. Include functions for enabling/disabling the cruise control; setting up the speed. The system should always maintain the speed unless there is a slower car in front of it. Make sure to define inputs and outputs. Do not forget that computer’s microprocessor works in very small steps (tiny steps!), so be careful not to assign large number of steps to one flowchart...
(Do the algorithm and flowchart) Write a C++ program that reads integer numbers and print it...
(Do the algorithm and flowchart) Write a C++ program that reads integer numbers and print it in horizontal order of the screen
-Draw a flowchart and pseudocode for a program that produces a monthly bill for a cell...
-Draw a flowchart and pseudocode for a program that produces a monthly bill for a cell phone customer. -List at least 10 separate modules that might be included. - For example, one module might calculate the charge for daytime phone minutes used. - -Make a working version of this program using Python. Need all of the above answered including the correct code for program using python
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT