Page 1 of 1

Needs to be in Python Please The user inputs a problem (S for sum or P for product) and a positive integer. Your program

Posted: Tue Jul 12, 2022 8:15 am
by answerhappygod
Needs to be in Python Please
The user inputs a problem (S for sum or P for product) and apositive integer. Your program will calculate and display the sumor product of integers from 1 to that number.
YOU MUST CREATE AND USE THESE METHODS IN YOUR PROGRAM. Youshould code and test your methods ONE at a time, do not focus onthe sample output to start.
getNum Receives no input. Prompts the user to enter a number.Use a loop to validate that the number is positive. Return theresult.
calcSum Receives a positive integer as input. USE AN ACCUMULATORto calculate the sum of the integers from 1 to this number. Returnthe result.
calcProd Receives an integer as input. USE AN ACCUMULATOR tocalculate the product of the integers from 1 to this number. Returnthe result.
Main should:
For example, if you input 5 as the number, and ā€˜S’, the programshould calculate 1 + 2 + 3 + 4 + 5 and display the sum as 15.
If you input 5 and ā€˜P’ the program should calculate 1 x 2 x 3 x4 x 5 and display the product as 120.
The process should repeat as long as the user wants to continue.This loop should be in main. DO NOT use System.exit command to endthe program.
Sample output: