Python Forum
Thread Rating:
  • 3 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function exercise
#3
sparkz_alot is correct, I would like to just add, that the question is slightly tricking you by using "imc" for the function name and a variable name.

basically, the first line is correct, the function is called imc, and two variable are being passed to the function, mass and height. These would come from elsewhere in a program and likely passed to the function something like:
something = imc(5, 4)
where
mass = 5 
height = 4
in my example here. So you have the values already given you and you use the variables of "mass" and "height" within your function.

You are then asked to modify the variable "imc" so you need to use a different varible, "answer", "x", "doris" anything will do so long as it obeys the python syntax and is not a keyword, but convention is to use something meaningful and descriptive (better to have a longer variable name and know what it is than just use "x" and not understand it in a months time).

Then you will be returning that variable from the function, so what ever variable you chose, will be the return values:
return answer
where "answer" is the variable I have just used.

You can always just write the function into a python prompt (don't forget the 4 space indentation on each line of the function) then once it is written, enter twice will have the function defined in memory, then simply go:
imc(10, 12)
or whatever values you want to test it.

I hope that clears it up a little, I found passing variables to and from functions a little tricky when I was first learning this.
Reply


Messages In This Thread
function exercise - by tdebeaulieu - Nov-16-2017, 11:23 PM
RE: function exercise - by sparkz_alot - Nov-17-2017, 01:48 AM
RE: function exercise - by iFunKtion - Nov-17-2017, 11:53 AM
RE: function exercise - by tdebeaulieu - Nov-20-2017, 04:50 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020