[Tutor] two input acceptions

adam urbas adamurbas at hotmail.com
Wed May 23 18:33:29 CEST 2007

I figured out why it was asking for the radius of a square.  It was because I had the if shape==1: thing on there.  I was typing in rectangle and that was an else: function.  How do i get it to accept both 1 and circle?  I learned not to use else: unless I was completely sure that I could use it, to avoid problems like this.I put both the .py and .txt files on there, so which ever you prefer.Thanks,Adam> To: tutor at python.org> From: alan.gauld at btinternet.com> Date: Sat, 19 May 2007 08:28:19 +0100> Subject: Re: [Tutor] two input acceptions> > > "Rolando Pereira" <finalyugi at sapo.pt> wrote> > what did you mean when you were talking about the raw_input( )?  > > How can the regular input( ) be used evilly?  > > raw_input() is the preferred way to read input from a user.> It only reads the raw input as typed by the user  so it always > returns a string which you then need to convert to another > type (like an int) if you need to. This gives you more controil > over what kind of data your program receives.> > input() by contrast reads the string input by the user and tries > to evaluate it as a Python expression. Thus if the user typed> > import os;os.system('format c:\')> > Python would try to evaluate that as a python string > and it could format your C drive. (In practice it would > throw up a prompt and hopefully you would say no!)> It might not be something as obvious as that, it > could simply deactivate your firewall, or add a new > user account to your PC, anything that enables a > subsequent attack to do more damage.> > The attack might not be deliberate, sometimes > accidentally typed errors can result in code being > executed that you didn't want.> > But thats why input() is best used in very strictly > controlled environments - like at the >>> prompt when > you are testing/developing code. But use raw_input plus > a conversion function for finished code.> > > When I run the program and input the rectangle option, > > it asks me for a radius, > > Your code is unreadable and I don't have the time > or inclination to try to unpick it. Can you send as plain > text or as an attachment please?> > Alan G> > _______________________________________________> Tutor maillist  -  Tutor at python.org> http://mail.python.org/mailman/listinfo/tutor
Create the ultimate e-mail address book. Import your contacts to Windows Live Hotmail.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070523/e28fae72/attachment.htm 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: area.py
Url: http://mail.python.org/pipermail/tutor/attachments/20070523/e28fae72/attachment.asc 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: area.txt
Url: http://mail.python.org/pipermail/tutor/attachments/20070523/e28fae72/attachment-0001.txt 

More information about the Tutor mailing list