Newbie question about evaluating raw_input() responses

Fábio Santos fabiosantosart at gmail.com
Wed May 22 02:35:18 EDT 2013


You have to convert `age` to an integer. Use int() to do it. Then you can
compare it to other numbers and obtain the expected results.
On 22 May 2013 07:29, "C. N. Desrosiers" <cndesrosiers at gmail.com> wrote:

> Hi,
>
> I'm just starting out with Python and to practice I am trying to write a
> script that can have a simple conversation with the user.
>
> When I run the below code, it always ends up printing response to "if age
> > 18:" -- even if I enter a value below 18.
>
> Can anyone point me to what I am doing wrong?  Many thanks in advance.
>
> age=raw_input('Enter your age: ')
> if age > 18:
>     print ('Wow, %s. You can buy cigarettes.' % age)
> else:
>     print ('You are a young grasshopper.')
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130522/3b95bbdc/attachment.html>


More information about the Python-list mailing list