Help with Time Calculator

Hey guys I need some help with my code here. I think I’m doing it correctly however the function doesn’t seem to be returning correctly. When I run and print it it, it prints “The new time is <function add_time at 0x00000271182F61F0>”

Here is my code ->

def add_time(start, duration):
    clock, period = start.split()
    hour, minute = clock.split(":")
    add_hours, add_minutes = duration.split(":")

    hour = int(hour) * 60
    minute = int(minute)

    add_hours = int(add_hours) * 60
    add_minutes = int(add_minutes)

    added_hours = hour + add_hours
    added_hours = added_hours / 60
    added_hours = int(added_hours)

    added_minutes = minute + add_minutes

    while added_minutes >= 60:
        added_hours = added_hours + 1
        added_minutes = added_minutes - 60

    added_minutes = str(added_minutes)
    added_hours = str(added_hours)
    print("New Hour:", added_hours)

    new_time = [added_hours, ":", added_minutes]

    print(added_hours, ":", added_minutes)

    return new_time


add_time("6:40 PM", "4:21")
print("The new time is", add_time)

Here is the output ->

New Hour: 11
11 : 1
The new time is <function add_time at 0x00000271182F61F0>

Process finished with exit code 0

you have asked to print the function here, writig add_time inside print
if you want the function result you need to call the function like you did in the line above

1 Like