Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.029 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'else:': 0.03; '"if': 0.09; 'subject:question': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; '18:': 0.16; 'integer.': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'advance.': 0.19; 'user.': 0.19; 'code,': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'script': 0.25; '>': 0.26; 'compare': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'anyone': 0.31; 'run': 0.32; 'url:python': 0.33; 'convert': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'doing': 0.36; 'thanks': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'starting': 0.37; 'expected': 0.38; 'ends': 0.38; 'obtain': 0.39; 'url:mail': 0.40; 'even': 0.60; 'results.': 0.60; 'numbers': 0.61; 'simple': 0.61; 'to:addr:gmail.com': 0.65; 'age': 0.80; 'age)': 0.84; '\xa0many': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=/srpQM1VvImDDeMpuoAGS+/9yaHnxu32c89jblihUfk=; b=OomcjqKg1csC0zKCBzPL7nh+XJeoZ2cjtc4AaZ5mHmbcKaHNVIoRa1IPeQr7n5y/pH arDpKq8Veu19e+CS92R891QvqBBR2HeR69z4d8GVM1iUqU9oZNbCEW0xnfas+XbmpBZ7 AnHxwwnSXk1leAibgF0zkqFL305nUs7otYn0WdkzAkGKWNcUJbehFvrDQUq/NMpyBrxL xAMy6ZEQCq4bHpmYHCP04/lJmgs0ENXzncgCDfrR9orSpOqANBOMJTZvkS/nvp+jP09t Bptv/K8/PaCM6LTE0Pp0hxGzCvFRC4aA6/WZ4TdV8BiV+No6xQg2j3EF9gaU7i8BMkYg o0lA== MIME-Version: 1.0 X-Received: by 10.224.61.1 with SMTP id r1mr5751913qah.93.1369204519343; Tue, 21 May 2013 23:35:19 -0700 (PDT) In-Reply-To: <534d7800-14c1-430b-85fb-dd703c2acc4d@googlegroups.com> References: <534d7800-14c1-430b-85fb-dd703c2acc4d@googlegroups.com> Date: Wed, 22 May 2013 07:35:18 +0100 Subject: Re: Newbie question about evaluating raw_input() responses From: =?ISO-8859-1?Q?F=E1bio_Santos?= To: "C. N. Desrosiers" Content-Type: multipart/alternative; boundary=001a11c3f4d4003d8804dd48c533 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 59 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369204522 news.xs4all.nl 15973 [2001:888:2000:d::a6]:58192 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45711 --001a11c3f4d4003d8804dd48c533 Content-Type: text/plain; charset=ISO-8859-1 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" 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 > --001a11c3f4d4003d8804dd48c533 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

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.<= /p>

On 22 May 2013 07:29, "C. N. Desrosiers&quo= t; <cndesrosiers@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? =A0Many thanks in advance.
age=3Draw_input('Enter your age: ')
if age > 18:
=A0 =A0 print ('Wow, %s. You can buy cigarettes.' % age)
else:
=A0 =A0 print ('You are a young grasshopper.')
--
http://mail.python.org/mailman/listinfo/python-list
--001a11c3f4d4003d8804dd48c533--