Last answered:

04 Apr 2020

Posted on:

03 Apr 2020

0

Error return outside function

While using the for loop. My code is working when using the print function but not working when using return. It is showing the error 'Error outside function' money_spent = 0 for i in prices:
if prices[i] >= 5:
money_spent = money_spent + (prices[i] * quantity[i]) return (money_spent)  
1 answers ( 0 marked as helpful)
Instructor
Posted on:

04 Apr 2020

1
Hi Srajan! Thanks for reaching out! How have you applied indentation to your code? Please make sure you comply with the syntax just as shown in the video (please don't forget that indentation in Python is crucial!). Then, return is used when you are defining a function. Here, instead, you are using a loop. We can't just add the return keyword when it does not regard the creation of a function. Hope this helps.
Best,
Martin

Submit an answer