Strange return when calling a function

1

I'm trying to do an exercise on functions in Python with the following statement: "Make a program that converts from 24-hour notation to 12-hour notation". Example: Convert 14:25 to 2:25 PM. The program should contain two functions, one that converts the time and another that prints the time (with AM or PM).

I've gotten to some extent, but now I'm doubtful why the program is not running.

My program:

hora = int(input("Digite a hora: "))

minuto = int(input("Digite os minutos: "))

def converter_hora(hora):

         return (hora -12)

def imprime_hora(hora,minuto):

        if(hora <= 12):
           print(hora,minuto,"AM")
        else:
           print(converter_hora,minuto,"PM")

print(imprime_hora)

Python is returning the following message:

  

function prints_time at 0x02D8C0C0

Any suggestions?

    
asked by anonymous 21.06.2017 / 04:05

1 answer

2

To make a call to a function, you must enter the name of the function, followed by parentheses. If the function has arguments, the values of these must be specified between () . In your case, you want to invoke the imprime_hora function, which has the arguments hora and minuto , then the function call must be something like:

print( imprime_hora(14, 25) )

Since, in this case, the values of hora and minuto are read from the user, you should do:

print( imprime_hora(hora, minuto) )

The same happens when you invoke the converter_hora function in:

print(converter_hora,minuto,"PM")

You should enter the value of the hora argument as follows:

print(converter_hora(hora), minuto, "PM")

In fact, since the imprime_hora function itself already prints the result, it is not necessary to print( imprime_hora(14, 25) ) , just do imprime_hora(14, 25) .

The final code, already correcting the indentation errors , is:

hora = int(input("Digite a hora: "))
minuto = int(input("Digite os minutos: "))

def converter_hora(hora):
    return (hora -12)

def imprime_hora(hora,minuto):
    if(hora <= 12):
        print(hora,minuto,"AM")
    else:
        print(converter_hora(hora), minuto, "PM")

imprime_hora(hora, minuto)
    
21.06.2017 / 04:35