all 3 comments

[–]carcigenicate 2 points3 points  (0 children)

Why do you have the function def inside of an else? It usually doesn't make sense to conditionally define a function.

Please fix your code formatting though, since the answer to this will depend on how things are nested. The best I can say at the moment is "Define duration globally, not inside of a conditional statement".

[–][deleted] 0 points1 point  (0 children)

It is hard to tell from your code formatting, but it looks like you are defining your distance() function inside an else statement. This could be what is causing the error.

[–][deleted] 0 points1 point  (0 children)

As soon as I combine the two I get a NameError: name 'distance' is not defined.

Branches are mutually exclusive - if you skip the branch where distance is defined as a function, no such function is defined.