Is it possible to return a variable and use it...?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nathan Pinno

    Is it possible to return a variable and use it...?

    Hello all,

    Is it possible to return a variable and then use it like the
    following:
    Code:
    dir exp_1:
    while hen != "*"
    sum = sum + hen
    return sum
    
    dir exp_2:
    if sum >= total_needed:
    print "Profit can be made."
    else:
    print "Expect a loss."
    
    total_needed = int(raw_input("What is the total eggs needed? "))
    hen = int(raw_input("How many eggs did each hen lay? Enter them in 1
    by 1 or enter * when done. "))
    exp_1
    exp_2
    If not, then how do I do so?

    Thanks,
    Nathan P.
  • Marc 'BlackJack' Rintsch

    #2
    Re: Is it possible to return a variable and use it...?

    On Sun, 02 Mar 2008 20:15:10 -0800, Nathan Pinno wrote:
    Hello all,
    >
    Is it possible to return a variable and then use it like the
    following:
    Code:
    dir exp_1:
        while hen != "*"
           sum = sum + hen
        return sum
    >
    dir exp_2:
       if sum >= total_needed:
         print "Profit can be made."
       else:
         print "Expect a loss."
    >
    total_needed = int(raw_input("What is the total eggs needed? "))
    hen = int(raw_input("How many eggs did each hen lay? Enter them in 1
    by 1 or enter * when done. "))
    exp_1
    exp_2
    >
    >
    If not, then how do I do so?
    Please work through the tutorial, then try to write actual Python code and
    come back if you have problems with your implementation of the program.
    Show us the real code and a description of either what error message you
    get, with full traceback, or if it does not raise an exception but just
    does not what you excpect it to do, tell us what you expected and what you
    get instead.

    Ciao,
    Marc 'BlackJack' Rintsch

    Comment

    • Alan Isaac

      #3
      Re: Is it possible to return a variable and use it...?

      Nathan Pinno wrote:
      Is it possible to return a variable and then use it


      I think you are asking about the ``global`` statement.

      <URL:http://docs.python.org/ref/global.html>


      like the following:


      Presumably not. ;-)



      Cheers,

      Alan Isaac


      Comment

      Working...