[Tutor] Outstanding Python Issue

Mark Lawrence breamoreboy at gmail.com
Tue Aug 11 19:39:51 EDT 2020


On 11/08/2020 20:27, eric grunfeld wrote:
> Hello Everyone:
> 
> I have been having some issues with this function in Python:
> 
> Here it is:
> 
> def convert_distance(miles):
>      km = miles * 1.6  # approximately 1.6 km in 1 mile
> return km
> 
> my_trip_miles = 55
> 
> This has been the response:
> 
> Error on line 4: return km ^ SyntaxError: 'return' outside function
> Because I am new to Python programming, I am sure that there is an easy
> solution.
> 
> I look forward to your thoughts/comments about this.
> 
> All the best,
> Eric
> 

It's exactly as the SyntaxError says, your 'return' is outside the 
function.  Remember that indentation matters in Python, so just line the 
'return' up with the line above and Bob's your uncle :)

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence



More information about the Tutor mailing list