Expected greater_than with test inputs 0 and 0 to return “These numbers are the same”

I’m getting the below error:

Expected greater_than with test inputs 0 and 0 to return “These numbers are the same”

Here is the question:

Write a function called greater_than that takes two integer inputs, x and y and returns the value that is greater. If x and y are equal, return the string “These numbers are the same”

Here is my code:

def greater_than(x, y):
  if x > y:
    return x
  if y > x:
    return y
  if x == y:
    return print("These numbers are the same")

test_numbers = greater_than(2, 4)

I’m not sure what I’m missing but it says my answer is wrong here.

Hi,

Remember that printing only outputs to the terminal (and doesn’t modify anything, or return anything).

If you want to return a string, you just put that string sans the print().

@jrb0831 What’s the difference you may ask if the same output appears in the terminal?

Let’s see:

def hi():
   return print("hi")

hi()
# output:
# hi

type( hi() )

#output:
# hi
# <class 'NoneType'>

def hello():
   return "hi"

hello()
# output:
# hi

type( hello() )
# output: 
# <class 'str'>

@jrb0831 There’s some programming joke/observation that the vast majority of the work programmers do is moving data from one place to another. It is in a way revealing because there’s a good amount of truth to that. When you write your lines of code think, how easy will it be to move this data around?

2 Likes

Ahh this makes so much more sense, thanks!

@toastedpitabread - read your updated reply and it was really helpful. The idea of moving data is helping mentally digest all of this. I’ll keep that in mind as I move forward. As always thanks!

1 Like