The sum of the scores


grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]
def grades_sum(scores):
    for i in scores:
    return s

well i think my code is perfect yet it shows me error saying did you forget to print the sum
return s should print the sum automatically but why isnt it doing it?
although when i added a print s command above the return all tests were passed


as Its saying!
print it!


to print a number..

print 6 #it will print 6

another thing to know,,,
when function returns a value ,It just handles you a value ,It does not prints for you.
You can catch this value inside a variable and print it or you can directly print it

for ex..

def Anyfunction():
    return 5

print Anyfunction() # will print 5


x = Anyfunction()

print x # will print 5

when you use print...

def Anyfunction():
    print 5

Anyfunction() # will print 5

But you wont be able to use the value with print but just print it,return makes function more powerful ,It can be used like a variable!


what is the difference between a return and a print statement?
both are returning values right?


I explained in the above post,do reply if you get that concept or not


okay i get it now to use the function further as a variable i have to use return and the print is for printing the value
but in the code i mentioned isn't the return s printing s ?


as i have seen in earlier programs that the return command has printed the results where there was no need for the print statement
in any function if an integer value has to be returned i always used return 'x' command and it printed that on the console!!


Nope,It just returning the value.

Think return as a employee of a function.
That only takes processed value from function and just returns it.
Then its work ends.

It does not print anything.


but what about this?


It was actually CC's interpreter that had printed values for you.


okay now i am confused.
return never printed my value on the console???


It was done by CodeCademy Interpreter (to show the result)

one good article to check out...


argh..they should have told me and i could have change my code for future programs

anyways you have been great help
thanks for giving it your time


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