need clarification on void function vs value returning function~python

Discussion in 'Homework Help' started by HCN1996, Mar 23, 2016.

  1. HCN1996

    Thread Starter New Member

    Nov 29, 2015
    26
    0
    Hello, I think I know what the difference is, but I havent been able to find a clear definition/example of each. I am posting my assignment code below which is supposed to have at least one value returning function, and one void function in it. I believe that I am using a value returning function with my functions slope() and/or slope2(). All the rest are void. Im not sure if I am right so any tips/further clarification would be greatly appreciated. My program works how it should, I am just looking for some help understanding functions from other eyes. Screen Shot 2016-03-23 at 12.05.26 AM.png Screen Shot 2016-03-23 at 12.05.30 AM.png Screen Shot 2016-03-23 at 12.05.32 AM.png
     
    Last edited: Mar 23, 2016
  2. WBahn

    Moderator

    Mar 31, 2012
    17,743
    4,795
    You say that you are using value returning functions with slope() and/or slope2(). Well, which is it?

    You say you think you know the difference but give no indication of what you think that difference is.

    The names are pretty descriptive. What do you think is required for a function to be a value-returning function?
     
    HCN1996 likes this.
  3. HCN1996

    Thread Starter New Member

    Nov 29, 2015
    26
    0
    I believe my value returning function is slope() and slope2() calls it. I have the impression that value returning functions are when a value is returned at the end and a void is when there is no return statement. However, I just have a feeling this isnt the case. Any help would be great. I know how to use functions well so far, but it bugs me that I dont completely know the difference between void and value returning functions. I would ask my teacher, but we are on spring break and I dont want to be a bother.
     
  4. WBahn

    Moderator

    Mar 31, 2012
    17,743
    4,795
    You basically have it.

    A value-returning function is a function that returns a value.

    A non-value-returning (i.e., void) function is a function that does not return a value.

    It's as simple as that.

    Now, one mistake your last post made is saying that it is void when there is no return statement.

    While not having a return statement will definitely make it a non-value-returning function, this is not required. A 'return' statement that does not have a value simply returns without returning a value -- making it a non-value returning function (at least that time).

    One problem (some say it's a feature -- and it can be) with Python is that the function definition doesn't spell out unambiguously whether it is value-returning or not.

    Consider

    Code (Python):
    1.  
    2. def WhoKnows(x):
    3.    if (x > 100):
    4.       return 5 * x;
    5.  
    Whether WhoKnows() returns a value or not depends on the value of x.
     
    HCN1996 likes this.
Loading...