PYTHON. Update the grade score program above to replace the static array with a dynamic array, and extend the array as e

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

PYTHON. Update the grade score program above to replace the static array with a dynamic array, and extend the array as e

Post by answerhappygod »

PYTHON. Update the grade score program above to replace thestatic array with a dynamic array, and extend the array as eachitem is added to the array. Continue accepting scores until theuser enters a negative value.
This is the Python code for the program I created and need toconvert the array to a Dynamic array, but I'm having troubleconverting it. Rather than post what I changed, I figured I wouldpost my working program. Keeping separate functions would beamazing, and thanks for the help!
def get_input(msg): num = int(input(msg)) return numdef get_scores(n_scores): nums = [0] * n_scores for i in range(0, n_scores): score = get_input("Enter score #{0}:".format(i + 1)) nums = score return nums
def get_high(nums): high = nums[0] for i in range(0, len(nums)): if nums > high: high = nums return highdef get_low(nums): low = nums[0] for i in range(0, len(nums)): if nums < low: low = nums return lowdef get_average(nums): sum = 0 for i in range(0, len(nums)): sum = sum + nums average = (sum / len(nums)) return averagedef display_output(highest_score, lowest_score,average_score): print('\nRESULTS:\n--------') print("The highest score is ={0}".format(highest_score)) print("The lowest score is ={0}".format(lowest_score)) print("The average of all scores is =" + "{0:.2f}".format(average_score))
def main(): n_scores = get_input('How many scores do you want toenter? ') nums = get_scores(n_scores)
highest_score = get_high(nums) lowest_score = get_low(nums) average_score = get_average(nums)
display_output(highest_score, lowest_score,average_score)
main()
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply