Question

In: Computer Science

def sum_gt_avg(num_list): Implement a function that returns the sum of the numbers in num_list that have...

def sum_gt_avg(num_list): Implement a function that returns the sum of the numbers in num_list that have a value greater than the average value in the list. • Parameters: num_list is a list of numbers (mixed integers and floats) • Examples: sum_gt_avg([1,2,3,4,5]) → 9 # 4+5

sum_gt_avg([1,2,3,-4,5]) → 10 # 2+3+5

sum_gt_avg([-1,-2,-3,-4,-5]) → -3 # -1-2

in python

Solutions

Expert Solution

\

def sum_gt_avg(num_list):
total = 0 # this holds the result
  
# taking average of the list
avg = sum(num_list) / len(num_list)
  
# looping through each number
for one in num_list:
if one > avg: # number is greater than average
total += one
  
# returning total
return total

# sample runs
print(sum_gt_avg([1,2,3,4,5]))
print(sum_gt_avg([1,2,3,-4,5]))
print(sum_gt_avg([-1,-2,-3,-4,-5]))

# Hit the thumbs up if you are fine with the answer. Happy Learning!


Related Solutions

Write a function that takes two integer inputs and returns the sum of all even numbers...
Write a function that takes two integer inputs and returns the sum of all even numbers between these inputs, and another function that takes two integer inputs and returns the sum of odd numbers between these inputs .In main function, the program will asks the user to enter two integer numbers and then passes them to these two functions and display the result of each of them
Write a function called alter_sum(n)that returns the alternating sum of all the numbers from 1 to...
Write a function called alter_sum(n)that returns the alternating sum of all the numbers from 1 to n so that the first number is added, the second number is subtracted, the third number added, the fourth subtracted, and so on: 1-2+3-4+5-6+7… until you reach n. If n is 0 or less then return 0.
(Python) Implement a function to compute a sum that can compute sum for an arbitrary number...
(Python) Implement a function to compute a sum that can compute sum for an arbitrary number of input integers or float numbers. In other words, calls like this should all work: flexible_sum(x1, x2) # sum of two integer or float numbers or strings x1 and x2 flexible_sum(x1, x2, x3) # sum of 3 input parameters and can also handle a single input parameter, returning it unchanged and with the same type, i.e.:   flexible_sum(1) returns 1 and can accept an arbitrary...
Program in java 1- Implement an algorithms to calculate the sum of all numbers in an...
Program in java 1- Implement an algorithms to calculate the sum of all numbers in an array.   2- Implement an algorithm to determine if an array has all unique integer values. 3- Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]). Return the running sum of nums. Example 1: Input: nums = [1,2,3,4] Output: [1,3,6,10] Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].
Make a function that calculates the summation of even numbers in the range. The function sum...
Make a function that calculates the summation of even numbers in the range. The function sum takes the two integer parameters and they are used as the range. The function uses default parameters for the range. When we call this function with one argument, it will be used as a starting point and the end of the range will be 100. Also, the function is called without any argument, the default range (0,100) will be used. We will use default...
A function calledsumOfFactorsthat takes n as a parameter and then returns the sum of the proper...
A function calledsumOfFactorsthat takes n as a parameter and then returns the sum of the proper factors/divisors ofn; for example,the sum of factorsof 20= 10+5+4+2 = 21.Note that 1 is nota properfactor of any number.Sample command => output:(display (sumOfFactors20))=> 21Hint: Calla recursivefunction sum_helperfrom sumOfFactorsfunction as follows:(define (sumOfFactors n)(sum_helper n (-n 1)))Here sum_helperfunction takes two parameters: n, d and returns the sum of all factors of n whichare <= d; for e.g. (sum_helper 20 6) returnsall proper factors of 20 which...
Modify the code below to implement the program that will sum up 1000 numbers using 5...
Modify the code below to implement the program that will sum up 1000 numbers using 5 threads. 1st thread will sum up numbers from 1-200 2nd thread will sum up numbers from 201 - 400 ... 5th thread will sum up numbers from 801 - 1000 Make main thread wait for other threads to finish execution and sum up all the results. Display the total to the user. #include <pthread.h> #include <stdio.h> #include <stdlib.h> #define N_OF_THREADS 4 void * print(void...
Implement the following functions in the given code: def babylonian_square_root(N, estimate, precision): This function is provided...
Implement the following functions in the given code: def babylonian_square_root(N, estimate, precision): This function is provided for you to use: def close_enough(x, y, maximum_allowable_difference): My biggest piece of advice to you is to go one line at a time and check your return values after each little change you make. Starter code: # There are different ways of implementing the same idea in math. # Today we will explore a simple way to calculate square roots. # # # #...
Write a Python program that calls a function to sum all the numbers in a list...
Write a Python program that calls a function to sum all the numbers in a list and returns the result to the caller. The main program creates a list (with hard-coded or user input) and passes the list as an argument to the function. You may not use the built-in function, sum. The program calls a second function to multiply all the numbers in a list passed to it by main and returns the product back to the caller. List...
import random # define functions def rollDice(): # function returns a random number between 1 and...
import random # define functions def rollDice(): # function returns a random number between 1 and 6 def userWon(t1, t2): # function accepts player total and computer total # function returns true if player wins # function returns false if computer wins def main(): # each player rolls two Dice player = rollDice() + rollDice() computer = rollDice() + rollDice() # ask the player if they want to roll again again = int(input("Please enter 1 to roll again. Enter 2...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT