[SOLVED] Why are my arguments undefined in python when I call my function?

Issue

I am trying to make a program which gives me the amount of minutes before the two boats collide. the boats are going 60 knot and 70 knot, and the distance between them is 455km. I get an error saying that route, boat_speed and crash is not defined.

def knot_to_km(knot):
    return (knot * 1.852)     

def time_of_impact(route, boat_speed, crash):
    route = 455
    boat_speed = (knot_to_km(60) + knot_to_km(70))
    crash = ((route / boat_speed) / 60)
    return(crash)

print(time_of_impact(route, boat_speed, crash))
    

Solution

A parameter is a value for input to a function, not for declaring a variable in a function.

def knot_to_km(knot):
    return (knot * 1.852)     

def time_of_impact():
    route = 455
    boat_speed = (knot_to_km(60) + knot_to_km(70))
    crash = ((route / boat_speed) / 60)
    return(crash)

print(time_of_impact())

or

def knot_to_km(knot):
    return (knot * 1.852)     

def time_of_impact(route, boat_speed):
    crash = ((route / boat_speed) / 60)
    return(crash)

route = 455
boat_speed = (knot_to_km(60) + knot_to_km(70))

print(time_of_impact(route, boat_speed))

Remember that the general way is the latter

Answered By – Desty

Answer Checked By – Willingham (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.