# Help with Python Control Flow Challenge

All code is at bottom of question

I wrote a function max_num(num1,num2,num3) which I expect to return the greatest value out of the 3 inputs, or return “It’s a tie!” if two or more of the values are equal. Instead of getting the suggested returns, I am getting the following:

10
-10
-5
It’s a Tie!

The only value that is returning incorrectly is -10; the other 3 values are correct. Can anyone please explain why this is happening? Thank you!

``````def max_num(num1,num2,num3):
if num1 > (num2 and num3):
return num1
elif num2 > (num1 and num3):
return num2
elif num3 > (num1 and num2):
return num3
else:
return "It's a tie!"

# Uncomment these function calls to test your max_num function:
print(max_num(-10, 0, 10))
# should print 10
print(max_num(-10, 5, -30))
# should print 5
print(max_num(-5, -10, -10))
# should print -5
print(max_num(2, 3, 3))
# should print "It's a tie"
``````
1 Like

I think it’s the way you’re using parenthesis.
should read more like: if num1 > num2 and num1 > num3:
return num1

more specifically, it’s getting stuck in your first if statement, try printing (num2 and num3) to see the difference between num1 > (num2 and num3) and num1 > num2 and num1 > num3

edit: just tested it and print(num2 and num3) print out as -30, so it does get you stuck

3 Likes

Hello @williamweiland762150, welcome to the forums! The issue maybe here (as with all of these conditions):

This is because this code basically checks to see if `num1` is greater than `True`. This is because here:

Basically checks to see if `num2` and `num3` are truthy values. So you are saying if `num1` is greater than thruthy (or indeed falsy), return that number.
I hope that helps!

2 Likes

Thank you kindly for your response!

Thank you as well, much appreciated!

1 Like

I’m gonna try to tackle this challenge this weekend…

1 Like

Here it is!! I am open to any and all criticisms!! This was really fun for me and I’m excited to see where the expansion of my knowledge will take me!

Hello! At a quick glance, the code looks good, and it seems to complete the project well! Just a thing I noticed is that for `card pick` and `heads or tails` you end certain bits of logic with an `elif`:

``````if (result == 1 and guess == "Heads") or (result == 2 and guess == "Tails"):
print("You won!")
return bet
elif (result == 1 and guess == "Tails") or (result == 2 and guess == "Heads"):
print("I'm sorry. Money please")
return -bet
``````

In this case, you could change the `elif` to an `else` and get rid of the condition. This is just a really minor thing, though.

1 Like

Oh yes!! Thank you for your input

1 Like