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
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...
Implement the following pseudocode in Python Consider the following pseudocode for a sorting algorithm: STOOGESORT(A[0 ......
Implement the following pseudocode in Python Consider the following pseudocode for a sorting algorithm: STOOGESORT(A[0 ... n - 1]) if (n = 2) and A[0] > A[1] swap A[0] and A[1] else if n > 2 m = ceiling(2n/3) STOOGESORT(A[0 ... m - 1]) STOOGESORT(A[n - m ... n - 1]) STOOGESORT(A[0 ... m - 1])
Using RAPTOR Create a flowchart and create the pseudocode for the following question Le Chef Heureux...
Using RAPTOR Create a flowchart and create the pseudocode for the following question Le Chef Heureux Restaurant has 20 tables that can be reserved at 5 p.m., 7 p.m., or 9 p.m. Design a program that accepts reservations for specific tables at specific times; the user enters the number of customers, the table number, and the time. Do not allow more than four guests per table or invalid table numbers or times. If an attempt is made to reserve a...
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...
Python English algorithm explanation Write a program that asks the user for the name of a...
Python English algorithm explanation Write a program that asks the user for the name of a file in the current directory. Then, open the file and process the content of the file. 1)If the file contains words that appear more than once, print “We found duplicates.” 2)If the file does not contain duplicate words, print “There are no duplicates.”
Python English algorithm explanation Write a program that asks the user for the name of a...
Python English algorithm explanation Write a program that asks the user for the name of a file in the current directory. Then, open the file and process the content of the file. 1)If the file contains words that appear more than once, print “We found duplicates.” 2)If the file does not contain duplicate words, print “There are no duplicates.”
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT