Python Forum

Full Version: A Problem With The Body of My Function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I'm writing here with only a slight degree of knowledge, but I think, I hope, this is the right place to ask the right questions.

Okay, I have set up code where I have to do the following:

perform a calculation underneath my header,

def volume(cargo):


THE BODY IS HERE.




Further down, I have the following assert commands

test_volume():

assert volume(cargo) = a number
assert volume(cargo) = a number

test_volume()

the number (a number) to the right of the assert command can't be greater than the total_net_load of the truck when it is MULTIPLIED BY THE CARGO, and … well … I HAVE THAT NUMBER for the total_net_load, and I have the number for the cargo in the expression after the assert commands (a number is written in), but how in the hell do I transfer this up to the function - WHICH I MUST USE THE RETURN FUCNTION FOR - so this is stored in the shell-memory?


I have thought up the following ''code''; but of course it fails.

def volume(cargo)
'''Statement here'''
total_net_load = x
cargo / total_net_load = a number
return <= a number

okay, I'm going to try this one out I have just wrote, but if it doesn't work i'm posting this question - thanks. didn't work: please, someone with a higher IQ than me, please point me in the right direction.


Also, I must add, i'm not looking for the answer, just a an explination of what where my thinking is wrong, thanks.
Working from your code, the def volume(cargo) statement needs a colon at the end.
Can't tell if your indentation is correct, please repost using proper tags. Indentation is critical.
total_net_load = x Where does the interpreter get the value for x?
Next line - It appears you do not understand assignment statements. The = means it is an assignment. They are in the format
<variable> = <expression>, not the other way around.
No idea what you are trying to do with the return statement. That needs to be in the format return <expression> where <expression> resolves to a variable.

Note that in Python variables are objects, so you can substitute the word object in any of the above.