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:
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.
-
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
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
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
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.'
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
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
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
>
> --
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
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
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
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
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
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:
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
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:
>
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
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'
19 matches
Mail list logo