-6

File "python", line 25 SyntaxError: 'return' outside function

total=0
for key in prices:
    sum=prices[key]*stock[key]
    print sum
    total=total+sum
return total
1
  • 2
    This error is self-explanatory. You can't return a value without defining a function. Commented Dec 21, 2015 at 18:26

1 Answer 1

0

Try relocating this code into a function.

For example:

#!/usr/bin/env python
prices = { 'Python': 100 }
stock = { 'Python': 20 }

def total_portfolio_value():
  total=0
  for key in prices:
    sum=prices[key]*stock[key]
    print sum
    total=total+sum
  return total

total_portfolio_value()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.