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


def sum_gt_avg(num_list): Implement a function that returns the sum of the numbers in num_list that have...
def count_pairs(num_list): Given a list of numbers num_list, count how many ways unique pairs of values from this list have a sum equal to a value anywhere in the list (including equaling one of the values being added). Watch out for duplicates – two locations may sum up to a value equal to many places in the list, but they only count as one pairing overall. The two summed values must be at unique locations in the list. • Parameters:...
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 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 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 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 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...
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' Remember, do not call input() or print() You must have at least one loop in each function. You cannot import any module. You cannot call any Python function...
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
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....
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...