Just Weight and See


#1

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])

return 0.1 * average(student["homework"]) + 0.3 * average(student["quizzes"]) + 0.6 * average(student["tests"])

when i click on save&submit it shows me like this.

Oops, try again. There seems to be something wrong with your code, see the console window for the error message!

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


#2

your return is wrongly indented, it should be indentend so that it is inside the function


#3

I'm assuming that your indentation is wrong, and you need to indent the line:

return 0.1 * average(student["homework"]) + 0.3 * average(student["quizzes"]) + 0.6 * average(student["tests"])

Also, you made the variables homework, quizzes, and tests to shorten your return statement, so you could really just write

return 0.1 * homework + 0.3 * quizzes + 0.6 * tests

Even better, when defining the variables homework, quizzes, and tests, you could multiply each thing, (average(student["homework"]), average(student["quizzes"]), average(student["tests"])), by their respective weights.


#4

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])

return 0.1 * homework + 0.3 * quizzes + 0.6 * tests

when i apply this code i am getting same message.

Oops, try again. There seems to be something wrong with your code, see the console window for the error message!

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


#5

me and @stetim94 both stated that you need to indent the line that your return is on so that it is inside of your function.


#6

i am unable to understand that what wrong in my function. Could you tell me where my code went wrong. I have written my code as per instructions.


#7

You have been told three times now.
Do you know how to indent? Just use the tab key.
Your return line:

return 0.1 * homework + 0.3 * quizzes + 0.6 * tests

needs to be indented.
Python creators made a design choice that indenting is necessary, so the correct syntax would be to have the return statement indented inside of the get_average function.
Please tell me that I was able to make sense?


#8

Hi Kyleaw,
I have written my code correct. but did not follow idented, First i did not understand your message. later you have explained me in detail. Now i com to know what i made mistake. I wish you all the best for your future. Thank for helping me.


#9

I'm glad I could help! Sorry I didn't explain well enough the first time. :slight_smile:


#10

its ok. Dont tell me sorry. we can be friends. and continue our journey.


#11

Not advisable. Use the recommended 4 spaces. Tab keys are configured differently in users' environments and are not always consistent.


#12

You're right, I was trying to get the point of indenting across but i neglected to think about that. Sorry!


#13

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.