Kent Johnson wrote:

Bob Gailer wrote:

At 04:43 AM 1/29/2005, Liam Clarke wrote:

< erk, to the list, to the List!>

if ( bad_weather =='y' ):
   # ask user only if weather is bad.
   b = input ( "Weather is really bad, still go out to jog?[y/n]" )
   if b == 'y':
      go_jogging()

Anyone else notice that he's never gonna go jogging if the weather is bad?
Unless I've got input() wrong, it only takes integers... ?



From the docs: input( [prompt]) Equivalent to eval(raw_input(prompt)).


So, it takes more than just integers, but it won't work the way the OP expects:
>>> print input('Type something: ')
Type something: 'spam ' * 4
spam spam spam spam
>>> print input('Type something: ')
Type something: y
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<string>", line 0, in ?
NameError: name 'y' is not defined
- because eval('y') looks for a variable named y


 >>> print input('Type something: ')
Type something: 'y'
y

It works with the quotes - it is evaluating a string literal

raw_input() would work better.

Kent

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Or you could just define a variable y and a variable n which equal "y" and "n", respectively. Using raw_input() is probably easier though.

--
Email: singingxduck AT gmail DOT com
AIM: singingxduck
Programming Python for the fun of it.

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to