473,396 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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:
Expand|Select|Wrap|Line Numbers
  1. dir exp_1:
  2. while hen != "*"
  3. sum = sum + hen
  4. return sum
  5.  
  6. dir exp_2:
  7. if sum >= total_needed:
  8. print "Profit can be made."
  9. else:
  10. print "Expect a loss."
  11.  
  12. total_needed = int(raw_input("What is the total eggs needed? "))
  13. hen = int(raw_input("How many eggs did each hen lay? Enter them in 1
  14. by 1 or enter * when done. "))
  15. exp_1
  16. exp_2
  17.  
  18.  
If not, then how do I do so?

Thanks,
Nathan P.
Mar 3 '08 #1
2 1066
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:
Expand|Select|Wrap|Line Numbers
  1. dir exp_1:
  2.     while hen != "*"
  3.        sum = sum + hen
  4.     return sum
  5. dir exp_2:
  6.    if sum >= total_needed:
  7.      print "Profit can be made."
  8.    else:
  9.      print "Expect a loss."
  10. total_needed = int(raw_input("What is the total eggs needed? "))
  11. hen = int(raw_input("How many eggs did each hen lay? Enter them in 1
  12. by 1 or enter * when done. "))
  13. exp_1
  14. exp_2
  15.  

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
Mar 3 '08 #2
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
Mar 3 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Aeon Twilight | last post by:
REFERENCE: http://us4.php.net/manual/en/function.include.php Example 16-7. include() through HTTP Example 16-10. include() and the return() statement -------------------- return.php...
0
by: Pieter Linden | last post by:
Okay, the basic plan: 1. Call EnumerateServers to return an array of all the computers on the network. available at: http://datafast.cjb.net/ 2. Resolve the HostNames into IP Addresses....
0
by: Cordell Lawrence | last post by:
Okay guys, We are wondering if this is a bug in Framework 2.0.40607 and looking for some clarification on the issue. Take a look at the folowing code. public delegate bool BoundryTest(int...
11
by: Brent Ritchie | last post by:
Hello all, I have been using C# in my programming class and I have grown quite fond of C# properties. Having a method act like a variable that I can control access to is really something. As...
3
by: KK | last post by:
Hello all, I have several classes binded by one common interface - say 'sum' interface which calculates the sum of all the class elements of type 'int'. class Alphabet { int _a; int _b; int...
13
by: Alison Givens | last post by:
....... that nobody knows the answer. I can't imagine that I am the only one that uses parameters in CR. So, my question again: I have the following problem. (VB.NET 2003 with CR) I have a...
28
by: beach.dk | last post by:
Hi, I'm trying to implement a simple hash algorith called rs_hash in javascript, but I cannot get a correct result. In c the code looks like this:
3
by: Goran | last post by:
Hi @ all! Is it possible to overload a member variable? Example: class ClassA_t {
4
by: Polaris431 | last post by:
If I have a method like this: private void DoSomething() { try { return true; } catch{} finally
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.