Is it correct? Please explain.
money_spent = 0
for i in prices:
money_spent += prices[i] * quantity[i]
return money_spent
Q: Why can't I use return in this function? What differentiates your solution?
1 answers ( 0 marked as helpful)
Hi Phongrada!
Thanks for reaching out.
You cannot use the return statement in a for loop. You should use the print command. When you use a function you can use both return and print, but return is more appropriate because you can reuse your functions in another functions, which is very useful.
Hope this helps.
Best,
Tsvetelin