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@python.org> From: [EMAIL PROTECTED]> Date: Sat,
19 May 2007 08:28:19 +0100> Subject: Re: [Tutor] two input acceptions> > >
"Rolando Pereira" <[EMAIL PROTECTED]> 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@python.org> http://mail.python.org/mailman/listinfo/tutor
_________________________________________________________________
Create the ultimate e-mail address book. Import your contacts to Windows Live
Hotmail.
www.windowslive-hotmail.com/learnmore/managemail2.html?locale=en-us&ocid=TXT_TAGLM_HMWL_reten_impcont_0507
#"Area calculation program"
print "Welcome to the Area calculation program"
print ""
print
# "Print out the menu:"
print "Please select a shape:"
print "1, Rectangle"
print "2, Circle"
#"Get the users choice:"
shape = input("> ")
#"Calculate the area:"
if shape == 1:
height = input("Please enter the height: ")
width = input("Please enter the width: ")
area = height*width
print "The area is", area
else:
radius = input("Please enter the radius: ")
area = 3.14*(radius**2)
print "The area is", area
#"Area calculation program"
print Welcome to the Area calculation program
print
print
# "Print out the menu:"
print Please select a shape:
print 1 Rectangle
print 2 Circle
#"Get the users choice:"
shape = input(> )
#"Calculate the area:"
if shape == 1:
height = input(Please enter the height: )
width = input(Please enter the width: )
area = height*width
print The area is, area
else:
radius = input(Please enter the radius: )
area = 3.14*(radius**2)
print The area is, area
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor