Is there a way to make it so that the one that should say 'its a tie' says 'its a tie', or do i have to do this the long way?

Write your max_num function here:

def max_num(num1, num2, num3):

   biggest_number = max(num1, num2, num3)

   return biggest_number

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!”

You can modify the max_num function to check if num1 , num2 , and num3 are all equal, and return the string “It’s a tie!” if they are:

def max_num(num1, num2, num3):
    if num1 == num2 == num3:
        return "It's a tie!"
    else:
        biggest_number = max(num1, num2, num3)
        return biggest_number

Then you can uncomment the print statement for print(max_num(2, 3, 3)) , and it should print “It’s a tie!” when num1 , num2 , and num3 are all equal.

1 Like

Thanks for your reply!
is there a way i can make this so that it also returns ‘it’s a tie’ if there are two biggest numbers?

def max_num(num1, num2, num3):
    if num1 == num2 == num3:
        return "It's a tie!"
    elif num1 == num2 or num1 == num3 or num2 == num3:
        return "It's a tie!"
    else:
        biggest_number = max(num1, num2, num3)
        return biggest_number

You can modify the max_num function to also return “It’s a tie!” if there are two or three biggest numbers. That way, if the numbers are all equal or two of them are equal, it will say “It’s a tie!” instead of showing one of the numbers as the biggest.

So, you can add an elif statement that checks if any two numbers are equal, and return “It’s a tie!” in that case. Otherwise, the function still returns the biggest number as before.

This modification makes the function more flexible and accounts for more scenarios. So, if you want to make sure the function handles ties properly, you can use this modified version.

let me know if this helps :slight_smile:

What happens if you try:

print(max_num(1, 1, 5))

You only want to print “It’s a tie!” if the largest number appears more than once.

1 Like

There are many ways to accomplish this task. You could try using the .count() method. Give it a shot.

I tried this, but it requires it to be a list, but when i change it to be a list it comes with more issues :pensive:

Post the code that you tried.

i removed it unfortunately. but i’m trying another thing just now will get back to you

edit: i have got it to work, thanks for everyone’s help!

1 Like

If you care to share your solution, you may receive some valuable feedback, but you’re under no obligation. Happy coding!

1 Like

Here was my solution

def max_num(num1, num2, num3):
values_amount = [num1, num2, num3]
amount_of_biggests = values_amount.count(max(num1, num2, num3))

if amount_of_biggests >=2:
return “It’s a tie!”
elif amount_of_biggests ==1:
return max(num1, num2, num3)

(it wont let me put in the indentations)

See How do I format code in my posts?

As for your code, good job getting the result you were after. You may want to consider a few things.
First, how can you DRY your code? (Don’t Repeat Yourself) You call the .max() method twice. Is there a way to only call it once?
Second, do you need the elif statement? When there are only 2 options, and the first condition isn’t met, we can simply execute the second option without testing the only other possible condition. For example:

def odd_or_even(num):
    if num % 2 == 0:
        return "Even"
    return "Odd" # Default return if the number isn't even
2 Likes