Complete the function definition to return the hours given minutes.

Complete the function definition to return the hours given minutes.

Sample output with input: 210.0

3.5
def get_minutes_as_hours(orig_minutes):

print(orig_minutes/60)

minutes = float(input())

print(get_minutes_as_hours(minutes))

I get the correct output but an unexpected extra line after. I don’t see what is wrong with it.

The Correct Answer and Explanation is:

Here’s the corrected version of your code:

def get_minutes_as_hours(orig_minutes):
    return orig_minutes / 60

minutes = float(input())
print(get_minutes_as_hours(minutes))

🔍 Explanation (300+ words):

The original version of your code:

def get_minutes_as_hours(orig_minutes):
    print(orig_minutes / 60)

minutes = float(input())
print(get_minutes_as_hours(minutes))

produces the correct numerical result (e.g., 3.5 for 210.0 input), but it also prints an unexpected extra line (specifically, None) after the result. This happens due to how the print() function and function return values work in Python.

Let’s break this down:

1. print() inside the function:

The line print(orig_minutes / 60) prints the value to the screen but does not return it. Since the function doesn’t include a return statement, Python automatically returns None by default. So when you do:

print(get_minutes_as_hours(minutes))

You are:

  • First printing orig_minutes / 60 inside the function,
  • Then printing the return value of the function, which is None.

Thus, your output looks like:

3.5
None

2. Correct Approach — Using return:

To fix this, replace print() inside the function with a return statement:

return orig_minutes / 60

Now the function returns the computed value (e.g., 3.5) to the caller, and then:

print(get_minutes_as_hours(minutes))

correctly prints the result once, without any None.

Summary:

  • Use return when you want to send a result back from a function.
  • Use print() only for displaying output, not for returning values.
  • Calling print() on a function that doesn’t return anything (or returns None) results in that None being printed.
Scroll to Top