473,387 Members | 1,876 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,387 software developers and data experts.

Is it possible to return variables to the main function?

Hi, I'm new to python, programming in general actually. I was wondering if it was possible to return variables from a function? Hmm that probably didn't make sense, i'll give an example. Lets say i had this program:
Expand|Select|Wrap|Line Numbers
  1. def main ():
  2.     age = input ('What is your age in years? ')
  3.     weeksOld = age * 52
  4.     print 'Wow, you are at least ', weeksOld, ' weeks old!!!'
  5. main ()
  6.  
Is it possible to separate the calculation into a function away from main and still have it return the variable for the print statement? I'll try and show you what i mean:
Expand|Select|Wrap|Line Numbers
  1. def main ():
  2.     age = input ('What is your age in years? ')
  3.     weeksOld (age)
  4.     print 'Wow, you are at least ', wsOld, ' weeks old!!!'
  5.  
  6. def weeksOld (years):
  7.     wsOld = years * 52
  8.     return wsOld
  9. main ()
  10.  
Sorry if that was hard to understand or if the question was rather nooby, as i said i'm new so try not to flame me too much, thanks!
Mar 18 '11 #1

✓ answered by Mariostg

Cameron,
Did you try it? You could answer this by yourself :)

Expand|Select|Wrap|Line Numbers
  1. def weeksOld (years): 
  2.     return = years * 52 
  3. main ()
  4.  

2 2184
Mariostg
332 100+
Cameron,
Did you try it? You could answer this by yourself :)

Expand|Select|Wrap|Line Numbers
  1. def weeksOld (years): 
  2.     return = years * 52 
  3. main ()
  4.  
Mar 18 '11 #2
Haha that was actually pretty simple :), thanks heaps!
Mar 18 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: JV | last post by:
Subject: Change variables from function Currently im working on writing login/verification scripts and I understand that leaving files that may contain sensitive information in the Document...
10
by: MJB | last post by:
In the main function of my form I check to see if the application is already running. If it is, I throw up a message box telling the user. What I would like to do is also maximize the...
7
by: Andrzej | last post by:
Is it possible to call a function which name is given by a string? Let assume that I created a program which call some functions for example void f1(void), void f2(void), void f3(void). ...
89
by: Sweety | last post by:
hi, Is main function address is 657. its show in all compiler. try it & say why? bye,
7
by: ballpointpenthief | last post by:
Hello, I'm thinking that it would be a good idea to start using the return code for main() to return the amount of memory still allocated (which would hopefully be zero) to ensure all memory has...
6
by: Ninan | last post by:
Is this a good design for myClass in the example below? Are there better alternatives for m_oA and myCallback? struct apiA, and function apiFn () are not in my control, as they are standard api...
1
by: shiniskumar | last post by:
i go tto perform some validation while ck=liking a button without refreshing the value.. i used ajax.My code is as follows...on button click i call the function validateGridAdd(); Inside tat...
28
by: ravi | last post by:
Hello everybody, I am writing a small application which does some work before the user main function starts execution. I am trying to #define the main function. But the problem is that,
27
by: junky_fellow | last post by:
Guys, Can I return 0, from main() ? Is this equivalent to exit(EXIT_SUCCESS) ? thanks for any help...
11
by: aarklon | last post by:
Hi all, I have heard many discussions among my colleagues that main is a user defined function or not. arguments in favour:- 1) if it is built in function it must be defined in some header...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.