Re: Beginner trying to understand functions.

2008-12-09 Thread Arnaud Delobelle
Ivan Illarionov <[EMAIL PROTECTED]> writes: > On Dec 8, 9:02 pm, simonh <[EMAIL PROTECTED]> wrote: >> Thanks for the many replies. Thanks especially to Pierre. This works >> perfectly: > > > >> def getAge(): >>     while True: >>         try: >>             age = int(input('Please enter your age:

Re: Beginner trying to understand functions.

2008-12-09 Thread Cedric Schmeits
the following would be nicer: def run(): get_name() a = get_age() check_age(a) again() if __name__ == "__main__": run() In this setup your script will only be run if it's started by itself, but when using a import, the functions from the script can be executed separately. -

Re: Beginner trying to understand functions.

2008-12-09 Thread Bruno Desthuilliers
simonh a écrit : Thanks for the extra tips Ivan and Bruno. Here is how the program looks now. Any problems? import sys def get_name(): name = input('Please enter your name: ') print('Hello', name) This one would be better spelled "get_and_display_name" !-) def get_age(): t

Re: Beginner trying to understand functions.

2008-12-09 Thread simonh
Thanks for the extra tips Ivan and Bruno. Here is how the program looks now. Any problems? import sys def get_name(): name = input('Please enter your name: ') print('Hello', name) def get_age(): try: return int(input('Please enter your age: ')) except ValueE

Re: Beginner trying to understand functions.

2008-12-09 Thread Ivan Illarionov
On Dec 8, 9:02 pm, simonh <[EMAIL PROTECTED]> wrote: > Thanks for the many replies. Thanks especially to Pierre. This works > perfectly: > def getAge(): >     while True: >         try: >             age = int(input('Please enter your age: ')) >             return age > >         except ValueErr

Re: Beginner trying to understand functions.

2008-12-09 Thread Bruno Desthuilliers
simonh a écrit : Thanks for the many replies. Thanks especially to Pierre. This works perfectly: (snip) Ok, now for some algorithmic stuff: def checkAge(age,min=18,max=31): if age in list(range(min, max)): print('Come on in!') elif age < min: print('Sorry, too young.'

Re: Beginner trying to understand functions.

2008-12-08 Thread Terry Reedy
cadmuxe wrote: i think we should use raw_input('Please enter your name: ') instead of input('Please enter your name: ') 3.0 input == 2.x raw_input 2.5 input == Posters: please include Python version used, as correct answers may depend on that. -- http://mail.python.org/mailman/listinfo/pyt

Re: Beginner trying to understand functions.

2008-12-08 Thread simonh
Thanks for the many replies. Thanks especially to Pierre. This works perfectly: def getName(): name = input('Please enter your name: ') print('Hello', name) def getAge(): while True: try: age = int(input('Please enter your age: ')) return age e

Re: Beginner trying to understand functions.

2008-12-08 Thread cadmuxe
On 12月8日, 下午10时53分, "James Mills" <[EMAIL PROTECTED]> wrote: > On Tue, Dec 9, 2008 at 12:46 AM, Peter Otten <[EMAIL PROTECTED]> wrote: > > I think the OP is using Python 3.0. What used to cause trouble > > Well of course he/she/it is! > I'm too blind to have noticed that! :) > > --JamesMills > > --

Re: Beginner trying to understand functions.

2008-12-08 Thread James Mills
On Tue, Dec 9, 2008 at 12:46 AM, Peter Otten <[EMAIL PROTECTED]> wrote: > I think the OP is using Python 3.0. What used to cause trouble Well of course he/she/it is! I'm too blind to have noticed that! :) --JamesMills -- -- -- "Problems are solved by method" -- http://mail.python.org/mailman/l

Re: Beginner trying to understand functions.

2008-12-08 Thread Peter Otten
James Mills wrote: > On Tue, Dec 9, 2008 at 12:24 AM, cadmuxe <[EMAIL PROTECTED]> wrote: >> i think we should use raw_input('Please enter your name: ') instead of >> input('Please enter your name: ') > > Good point :) OP: Please take notes :) I think the OP is using Python 3.0. What used to caus

Re: Beginner trying to understand functions.

2008-12-08 Thread Benjamin Kaplan
On Mon, Dec 8, 2008 at 9:24 AM, cadmuxe <[EMAIL PROTECTED]> wrote: > i think we should use raw_input('Please enter your name: ') instead of > input('Please enter your name: ') > Print is a function in this code and range returns an iterator (or else list(range(18,31)) is redundant). I think the O

Re: Beginner trying to understand functions.

2008-12-08 Thread James Mills
On Tue, Dec 9, 2008 at 12:24 AM, cadmuxe <[EMAIL PROTECTED]> wrote: > i think we should use raw_input('Please enter your name: ') instead of > input('Please enter your name: ') Good point :) OP: Please take notes :) cheers James -- -- -- "Problems are solved by method" -- http://mail.python.org

Re: Beginner trying to understand functions.

2008-12-08 Thread cadmuxe
i think we should use raw_input('Please enter your name: ') instead of input('Please enter your name: ') 2008/12/8 Peter Otten <[EMAIL PROTECTED]> > simonh wrote: > > > In my attempt to learn Python I'm writing a small (useless) program to > > help me understand the various concepts. I'm going to

Beginner trying to understand functions.

2008-12-08 Thread acerimusdux
simonh write: In my attempt to learn Python I'm writing a small (useless) program to help me understand the various concepts. I'm going to add to this as I learn to serve as a single place to see how something works, hopefully. Here is the first approach: name = input('Please enter your name:

Re: Beginner trying to understand functions.

2008-12-08 Thread Peter Otten
simonh wrote: > In my attempt to learn Python I'm writing a small (useless) program to > help me understand the various concepts. I'm going to add to this as I > learn to serve as a single place to see how something works, > hopefully. Here is the first approach: > That works fine. Then I've trie

Re: Beginner trying to understand functions.

2008-12-08 Thread Pierre-Alain Dorange
simonh <[EMAIL PROTECTED]> wrote: > def getName(): > name = input('Please enter your name: ') > print('Hello', name) > > def getAge(): > while True: > try: > age = int(input('Please enter your age: ')) > break > except ValueError: >

Re: Beginner trying to understand functions.

2008-12-08 Thread James Mills
On Mon, Dec 8, 2008 at 11:32 PM, simonh <[EMAIL PROTECTED]> wrote: > That works fine. Then I've tried to use functions instead. The first > two work fine, the third fails: [ ... snip ... ] Try this: def getName(): name = input('Please enter your name: ') print('Hello', name) return name

Beginner trying to understand functions.

2008-12-08 Thread simonh
In my attempt to learn Python I'm writing a small (useless) program to help me understand the various concepts. I'm going to add to this as I learn to serve as a single place to see how something works, hopefully. Here is the first approach: name = input('Please enter your name: ') print('Hello'