Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can someone help me with my code problem?

Write a function called check_values that has three parameters: x, y, and z. Every value passed to each of these parameters will be an integer. This function should return True if all three variables sum to a positive number or if at least two of the variables hold positive values. Otherwise this function should return False.

Below is my code:

def check_values(x, y, z):
    if x+y+z >= 0:
        return True
    elif (x or y >=0) or (y or z >=0) or (x or z >= 0):
        return True
    else:
        return False
    x = int(input('Enter X value: '))
    y = int(input('Enter Y value: '))
    Z = int(input('Enter Z value: '))

I failed this assert check:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

assert not check_values(1, -1, -1), "this should return False, not True (or any other value)"

How do I fix this? Also is there a better way to do the check "if at least two of the variables hold positive values"?

>Solution :

The elif statement does not work this way.
You should write:
elif (x>=0 and y>=0) or ...:

Does this help?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading