Question

python Write a function called has_odd_even that takes three integers as parameters and that returns True...

python

  1. Write a function called has_odd_even that takes three integers as parameters and that returns True if there is at least one odd and at least one even among the three numbers and that returns False otherwise. Below are some sample calls and the appropriate value to return.

Function call

Value returned

has_odd_even(2, 4, 6)

False

has_odd_even(2, 3, 4)

True

has_odd_even(12, 4, 17)

True

has_odd_even(5, 17, 4)

True

has_odd_even(14, 7, 5)

True

has_odd_even(5, 4, 2)

True

has_odd_even(13, 20, 91)

True

has_odd_even(7, 19, 5)

False

You may assume that all three integers passed to your function are greater than or equal to 0.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def has_odd_even(n1, n2, n3):
    return (n1 % 2 == 0 or n2 % 2 == 0 or n3 % 2 == 0) and (n1 % 2 == 1 or n2 % 2 == 1 or n3 % 2 == 1)


# Testing the function here. ignore/remove the code below if not required
print(has_odd_even(2, 4, 6))
print(has_odd_even(2, 3, 4))
print(has_odd_even(12, 4, 17))
print(has_odd_even(5, 17, 4))
print(has_odd_even(14, 7, 5))
print(has_odd_even(5, 4, 2))
print(has_odd_even(13, 20, 91))
print(has_odd_even(7, 19, 5))

Add a comment
Know the answer?
Add Answer to:
python Write a function called has_odd_even that takes three integers as parameters and that returns True...
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
  • 1. Write a function named findTarget that takes three parameters: numbers, an array of integers -...

    1. Write a function named findTarget that takes three parameters: numbers, an array of integers - size, an integer representing the size of array target, a number The function returns true if the target is inside array and false otherwise 2. Write a function minValue that takes two parameters: myArray, an array of doubles size, an integer representing the size of array The function returns the smallest value in the array 3. Write a function fillAndFind that takes two parameters:...

  • 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...

  • in python A. Define a function called contains_only_integers() that takes a tuple, returns True if all...

    in python A. Define a function called contains_only_integers() that takes a tuple, returns True if all the items in the tuple are integers(2), and returns False otherwise. For example, contains_only_integers (3, 5, 17, 257, 65537) ), contains_only_integers( (-1,) ), and contains_only_integers( ) should all return True, but contains_only_integers (2.0,4.0)) and contains_only_integers (8, 4, "2", 1)) should both return false. Your function should use a while loop to do this calculation. 121 Hint: the is instance() built-in function provides the most...

  • In c++ 1. Write a function named findTarget that takes three parameters - numbers: an array...

    In c++ 1. Write a function named findTarget that takes three parameters - numbers: an array of integers size: an integer representing the size of array target: a number The function returns true if the target is inside the array and false otherwise 2. Write a function min Valve that takes two parameters: myArray an array of doubles - size: an integer representing the size of array The function returns the smallest value in the array 3 Wrile a funcion...

  • Write a function named findTarget that takes three parameters: - numbers, an array of integers -...

    Write a function named findTarget that takes three parameters: - numbers, an array of integers - size, an integer representing the size of array - target, a number The function returns true if the target is inside array and false otherwise

  • Implement function allEven() that takes a list of integers and returns True if all integers in...

    Implement function allEven() that takes a list of integers and returns True if all integers in the list are even, and False otherwise. >>> allEven([8, 0, -2, 4, -6, 10]) True >>> allEven([8, 0, -1, 4, -6, 10]) False

  • Problem 1. Write a Python function times_i_at_odd(L) that takes as arguments a list L and returns...

    Problem 1. Write a Python function times_i_at_odd(L) that takes as arguments a list L and returns a list consisting of the elements of L multiplied by the index number of the element at odd positions. (Use list comprehensions) >>> times_i_at_odd([1,2,3,4,5,6,7,8,9,10]) [2, 12, 30, 56, 90] Problem 2. Write a recursive function sum_cols(grid, n) that takes a list of lists of integers grid and integer n and returns the sum of column n in grid. For example, the call sum_cols([[1,2,3,4], [10,20,30,40],...

  • (Must be written in Python) You've been asked to write several functions. Here they are: yourName()...

    (Must be written in Python) You've been asked to write several functions. Here they are: yourName() -- this function takes no parameters. It returns a string containing YOUR name. For example, if Homer Simpson wrote this function it would return "Homer Simpson" quadster(m) -- this function takes a value m that you pass it then returns m times 4. For example, if you passed quadster the value 7, it would return 28. isRratedMovieOK(age) -- this function takes a value age...

  • In C++, write a function isOdd() that takes one integer parameter. The function returns true if...

    In C++, write a function isOdd() that takes one integer parameter. The function returns true if the number if odd and false otherwise.

  • please use python to solve Problem 4 (a) Write a function is_sum_squares (n) that returns True...

    please use python to solve Problem 4 (a) Write a function is_sum_squares (n) that returns True if n can be written as a² + b2 , where a, b are integers, and False otherwise. For example is_sum_squares (5) is True since 5 = 12 + 22, while is_sum_squares (3) is False. (b) Compute is_sum_squares (7), is_sum_squares (11), is_sum_squares (13), is_sum_squares(17), is_sum_squares (19), is_sum_squares (23). (c) What is the pattern for is_sum_squares(p) when p is prime. (HINT: look at p %...

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