Question

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def sum_gt_avg(num_list):
    # Calculating sum
    s = 0
    for x in num_list:
        s += x
    # Calculating average
    avg = s/len(num_list)
    # Calculating sum greater tha average
    s = 0
    for x in num_list:
        if(x > avg):
            s += x
    # Returning calculated sum
    return s

# testing
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]))

Add a comment
Know the answer?
Add Answer to:
def sum_gt_avg(num_list): Implement a function that returns the sum of the numbers in num_list that have...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • def gravitate(nums, direction): Description: o Apply "sideways gravity" to nums by combining all the numbers in...

    def gravitate(nums, direction): Description: o Apply "sideways gravity" to nums by combining all the numbers in toone , placing the result on one side in some direction, replacing all the other numbers with zeroes. Also return nums when done. Assumptions: o nums is a two-dimensional list of numbers (floats, or integers) o direction is a string, either "left" or "right" Restrictions: o You need to modify the list in-place, and also return it. Updates: o We'd not intended it, but...

  • def zigzag(text): Implement a function that takes a string and returns a new string that is...

    def zigzag(text): Implement a function that takes a string and returns a new string that is a zig-zag rearrangement of it like the one in the examples below. • Parameters: text is a string (no validation needed) • Examples: zigzag('12345678') → '18273645' zigzag('123456789') → '192837465' zigzag('abcdefgh') → 'ahbgcfde' zigzag('GeorgeMason') → 'GneoosragMe' in python

  • PYTHON The function longest that returns the longest of two strings. The function count_over that takes...

    PYTHON The function longest that returns the longest of two strings. The function count_over that takes a list of numbers and an integer nand returns the count of the numbers that are over n. The function bmi that takes two parameters height and weight and returns the value of the body mass index: a person's weight in kg divided by the square of their height in meters. def longest(string1, string2): """Return the longest string from the two arguments, if the...

  • Python 1 Write a function called sum_odd that takes two parameters, then calculates and returns the...

    Python 1 Write a function called sum_odd that takes two parameters, then calculates and returns the sum of the odd numbers between the two given integers. The sum should include the two given integers, if they are odd. You can assume the arguments will always be positive integers, and the first smaller than or equal to the second. 3 To get full credit on this problem, you must define at least 1 function, use at least 1 loop, and use...

  • Question 1a - Increasing Numbers in List - First Occurence(3 points) Write a function numIncreasing1(L) that...

    Question 1a - Increasing Numbers in List - First Occurence(3 points) Write a function numIncreasing1(L) that takes as input a list of numbers and returns a list of the first sequence within that is increasing order, and has a length of at least 2. If no increasing sequential numbers are found, (ie. the input list is in descending order) then naturally a list of just the first value is returned. Increasing sequence means for a number to be valid it...

  • Implement the function odd_total (xs) that takes a list of list of ints xs and returns...

    Implement the function odd_total (xs) that takes a list of list of ints xs and returns the sum of the odd numbers but skips the numbers on the first row and the last column of xs. You're not allowed to modify xs. You can't use any built-in function or method except int, str, range and len. Example: odd_total ([[1,2,3],[4,5,6], [7,8,9]]) - - > 12

  • 1. Write a recursive function that returns the sum of all even integers in a LinkedBinaryTree. Yo...

    please explain each line of code! ( in python ) 1. Write a recursive function that returns the sum of all even integers in a LinkedBinaryTree. Your function should take one parameter, root node. You may assume that the tree only contains integers. You may not call any methods from the LinkedBinaryTree class. Specifically, you should traverse the tree in your function def binary tree even sum (root): Returns the sum of al1 even integers in the binary tree 2....

  • Using Blitz3D 1. This function returns the sum of five numbers 2. This function returns the quoti...

    please help this function using Blitz3D Using Blitz3D 1. This function returns the sum of five numbers 2. This function returns the quotient of dividing a smaller number by the larger # 3. This function returns the difference... 4. A product function Eg. start with Function NameOfFunction Code.... here End Function Using Blitz3D 1. This function returns the sum of five numbers 2. This function returns the quotient of dividing a smaller number by the larger # 3. This function...

  • Use Python [12] 10. Complete the code for the function documented below. Note that the function...

    Use Python [12] 10. Complete the code for the function documented below. Note that the function gets all its input from the parameters and not from the keyboard. It returns all information to the calling function and not to the computer display def frstiggest la, b, c) 'Assume a, b, and c are integers. Return True if a is greater than both b and c, Examples anh False otherwise would be True; firstigges (9, 6, 7) and firstBiagest (4, -2,...

  • ****python**** Q1. Write a recursive function that returns the sum of all numbers up to and...

    ****python**** Q1. Write a recursive function that returns the sum of all numbers up to and including the given value. This function has to be recursive; you may not use loops! For example: Test Result print('%d : %d' % (5, sum_up_to(5))) 5 : 15 Q2, Write a recursive function that counts the number of odd integers in a given list. This function has to be recursive; you may not use loops! For example: Test Result print('%s : %d' % ([2,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT