Newbie question about evaluating raw_input() responses

Alister alister.ware at ntlworld.com
Wed May 22 18:31:04 EDT 2013


On Tue, 21 May 2013 23:52:30 -0700, Kevin Xi wrote:

> On Wednesday, May 22, 2013 2:23:15 PM UTC+8, C. N. Desrosiers wrote:
>> Hi,
>> 
> 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.
>> 
> So you may want to search the doc before you ask: http://docs.python.org
>> 
>> 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.')
> 
> You can either use `raw_input` to read data and convert it to right
> type, or use `input` to get an integer directly. Read this:
> http://docs.python.org/2/library/functions.html#raw_input
> http://docs.python.org/2/library/functions.html#input
> 
>                                                                      
Kevin

Please write out 1000 time (without using any form of loop)

"NEVER use input in python <3.0 it is EVIL"*

as Chris A point out it executes user input an can cause major damage 
(reformatting the hard disk is not impossible!)


-- 
Quality Control, n.:
	The process of testing one out of every 1,000 units coming off
	a production line to make sure that at least one out of 100 works.



More information about the Python-list mailing list