Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program to randomly generate integer data values into an array that can hold 25 values. The program should ask the user to enter
- Write a program to randomly generate integer data values into an array that can hold 25 values. The program should ask the user to enter the minimum and maximum values in a numeric range that is not less than 1 and not greater than 500. Validate that the user enters the numbers correctly (minimum first >= 1 and then maximum <= 500) and correct the errors if not. The program should then generate 25 random numbers in that range and store them in the array. After filling the array, the program should calculate the total of all the values that are even numbers and the total of all the values that are odd numbers. Then the program should calculate the square root of each of those totals (hint: math library function). Display all 25 values in the array. Display the total of the even numbers and the square root of that total. Display the total of the odd numbers and the square root of that total.
- Required Functions:
- A function that reads and validates the minimum and maximum values that the user enters. This will require reference parameters in order to return both values to the function call.
- A function that can generate random numbers in a sequential range and return the number generated. This function should be able to work with any sequential range of numbers not specific to this program.
- A function that will calculate the total of the even numbers and the total of the odd numbers in the array. This function will have to use two parameters passed by reference to store the totals. The function will also need an array parameter that cannot be modified in the function. The function will also need a parameter to store the size of the array which cannot be modified in the function. A function to display the array.
Step by Step Solution
★★★★★
3.46 Rating (159 Votes )
There are 3 Steps involved in it
Step: 1
import random import math def main size 25 start end rangeinput numarr arraygenstart end size ev...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started