Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading