Question

PYHTON Write a function which takes a single parameter. The parameter is a list of integers....

PYHTON

Write a function which takes a single parameter. The parameter is a list of integers. Your function should return a count of the number of integers in the list which are odd

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def count_odds(lst):
    count = 0
    for num in lst:
        if num % 2 == 1:
            count += 1
    return count


# Testing the function here. ignore/remove the code below if not required
print(count_odds([3, 1, 9, 5]))
print(count_odds([2, 4, 8, 0]))
print(count_odds([2, 9, 1, 5, 6, 3, 0]))
Add a comment
Know the answer?
Add Answer to:
PYHTON Write a function which takes a single parameter. The parameter is a list of integers....
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
  • Write a C++ function that takes a pointer to an array of integers as a parameter...

    Write a C++ function that takes a pointer to an array of integers as a parameter and return the number of prime integers in the array. Write main() program to test the function.

  • write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple

    1 write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple. Hint (can be done in one pass, you are not allowed to use built-on min and max functions.)max, min = find_max_min(my_list):2 write a Python function that takes in a list of integers (elements), and an integer number (num). The functions should count and return number of integers in elements greater than, less than, and equal to...

  • Write a function that takes, as an argument, a list of positive integers and a target...

    Write a function that takes, as an argument, a list of positive integers and a target value, and returns the number of times that the target value appears in the list. Call this function problem1(myList, target). For example, >>>problem1([1,2,3,4,5,6,5,4,3], 5) should return 2, and >>>problem1([1,2,3,4,5,6,5,4,3], 7) should return 0.

  • Write a recursive function sum-odds that takes a non-empty list of integers

    in python Part I: Sum of Odd Integers Write a recursive function sum-odds that takes a non-empty list of integers as an argument and returns the sum of only the odd integers in the list. In class we explored a recursive function called rsum that recursively computes the sum of a list of integers use it as a model to get started. Your function must be recursive and must not use any loops

  • Use the FDR to design and write a function, maxValTimes, that takes a list of integers...

    Use the FDR to design and write a function, maxValTimes, that takes a list of integers and returns a set containing the value(s) that occur the same number of times as the maximum value in the list. If the list is empty, return an empty set.   For example if the list was [2,1,1,2,3,3,1] the function would return {2,3} as the maximum value is 3 which occurs twice, and 2 also occurs twice (but 1 occurs 3 times). For full marks,...

  • C++ 2. (a) Write a function, printdixisors, that takes a single integer parameter and prints all...

    C++ 2. (a) Write a function, printdixisors, that takes a single integer parameter and prints all the numbers less that the parameter that are divisors of the parameter (i.e. divides it without a remainder) including 1. So printdivisors(6) will print 1,2,3. Note you may use a wrapper function or default parameters. (b) Write a function, sumdixisors, that takes a single integer parameter and returns the sum of all the divisors of the parameter (including 1). So sumdivisors(6) will return 6...

  • Write function all_coprime_pairs( ) which takes as input a list, L, with positive unique integers (i.e....

    Write function all_coprime_pairs( ) which takes as input a list, L, with positive unique integers (i.e. no duplicated integers), and should return: 1. List (of tuples) containing all pairs of numbers in L that are coprime. 2. Empty list, If no pair of numbers in L is coprime. Your solution must include a function call to the function coprime designed in the previous question. The order of the tuples or the order of the two numbers within the tuples is...

  • Write a Scheme function DEL-LELEMENT that takes a list as a parameter and returns a list...

    Write a Scheme function DEL-LELEMENT that takes a list as a parameter and returns a list identical to the parameter except the last element has been deleted. For example, (DEL-LELEMENT '(8 2 3 7 6)) should return (8 2 3 7) *Please explain your code and submit the source code. Please test the function with the provided example and submit a screen shot of the testing result.

  • Python 3 Write a function named inverse that takes a single parameter, a dictionary. In this...

    Python 3 Write a function named inverse that takes a single parameter, a dictionary. In this dictionary each key is a student, represented by a string. The value of each key is a list of courses, each represented by a string, in which the student is enrolled. The function inverse should compute and return a dictionary in which each key is a course and the associated value is a list of students enrolled in that course. For example, the following...

  • Write a python function alt which takes a list of strings myList as a parameter. alt...

    Write a python function alt which takes a list of strings myList as a parameter. alt then returns two strings s1 and s2 as a tuple (s1, s2). Here s1 is the concatenation of the strings in myList in even index positions, and s2 is the concatenation of the strings in myList in odd index positions. (List starts at index 0) For example, if myList = [‘My’, ‘kingdom’, ‘for’, ‘a’ , ‘horse’], then s1 = ‘Myforhorse’ and s2 = ‘kingdoma’.

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