Python Practice Module-Control Flow

I am running through practice modules in python and I came across this exercise. It will not accept my code. I get the correct answers, but my solution differs from the correct solution. The correct return for each conditional statement looks like this:

return (num1)

and mine (posted below) is this:

return str(num1) + " is the largest number!"

I assumed I had to transform the integer into a string. Was my solution marked incorrect for the extra detail I put into it? Or because the output was not achieved in the correct manner?

# exercise material
Create a function called max_num() that has three parameters named num1, num2, and num3.

The function should return the largest of these three numbers. If any of two numbers tie as the largest, you should return "It's a tie!".

#initial function call

def max_num(num1, num2, num3):
  if num1 > num2 and num1 > num3:
    return str(num1) + " is the largest number!"
  elif num2 > num1 and num2 > num3:
    return str(num2) + " is the largest number!"
  elif num3 > num1 and num3 > num2:
    return str(num3) + " is the largest number!"
  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!"

#output
10 is the largest number!
5 is the largest number!
-5 is the largest number!
It’s a tie!

So, your code works with passing different arguments? (and not just the ones supplied).

You wouldn’t be the first person here who had written different workable code that didn’t pass the backend tests for these challenges. :slight_smile:
People can interpret questions differently and will certainly write different code. There’s not always just one way to write it. Maybe you came up with a better way to write it (more efficient or something). But, it’s difficult to read your post and reproduce results b/c it’s not formatted.

So, going forward…if you could please format your code it would be helpful. It’s difficult for people to read it as it is & for anyone to try to push you in the direction of fixing it if needed. (Python relies on indentation…and you might have an indentation error). Use the </> button or click on the gear icon.

I was curious about how to format this post, I appreciate the link and the feedback.

1 Like