[Tutor] trouble with "if"
adam urbas
adamurbas at hotmail.com
Wed May 23 18:46:32 CEST 2007
Thanks Andre. That solved most of the problems. Now all the lists will run correctly, but when I input a radius, it says:can't multiply sequence by non-int of type 'float'When it displays that, it is talking about circumference=(radius*2*3.14). I'm guessing it doesn't want me to multiply by pi. PLEASE HELP!!!thanks in advance,Adam> Date: Wed, 23 May 2007 18:08:20 +0200> From: andreengels at gmail.com> To: adamurbas at hotmail.com> Subject: Re: [Tutor] trouble with "if"> CC: tutor at python.org> > The problem is with types. The outcome of raw_input is a string. But> if you give the line:> > if shape == 1:> > you are comparing it with a number. The text "1" is not equal to the> number 1, so this evaluates to False.> > Instead you should do:> > if shape == "1":> > To also be able to type 'circle' instead of '1', you can do:> > if shape == "1" or shape == "circle":> > or alternatively:> > if shape in ["1","circle"]:> > > > Andre Engels> > 2007/5/23, adam urbas <adamurbas at hotmail.com>:> >> > Hi all,> >> > I've been working with this new program that I wrote. I started out with it> > on a Ti-83, which is much easier to program than python. Now I'm trying to> > transfer the program to python but its proving to be quite difficult. I'm> > not sure what the whole indentation thing is for. And now I'm having> > trouble with the if statement things.> >> > #"Circle Data Calculation Program:"> > print "Welcome to the Circle Data Calcuation Program."> > print> >> > #"Menu 1:"> > print "Pick a shape:"> > print "(NOTE: You must select the number of the shape and not the shape> > itself)"> > print "1 Circle"> > print "2 Square"> > print "3 Triangle"> >> > #"User's Choice:"> > shape=raw_input("> ")> >> > #"Select Given:"> > if shape == 1:> > print "Choose the given value:"> > print "1 radius"> > print "2 diameter"> > print "3 circumference"> > print "4 area"> >> > #"User's Choice:"> > given=raw_input("> ")> >> > if given == 1:> > radius=raw_input("Enter Radius:")> > diameter=(radius*2)> > circumference=(diameter*3.14)> > area=(radius**2*3.14)> > print "Diameter:", diameter> > print "Circumference:", circumference> > print "Area:", area> >> > if given == 2:> > diameter=raw_input("Enter Diameter:")> > radius=(diameter/2)> > circumference=(diameter*3.14)> > area=(radius**2*3.14)> > print "Radius:", radius> > print "Circumference:", circumference> > print "Area:", area> >> > if given == 3:> > circumference=raw_input("Enter Circumference:")> > radius=(circumference/3.14/2)> > diameter=(radius*2)> > area=(radius**2*3.14)> > print "Radius:", radius> > print "Diameter:", diameter> > print "Area:", area> >> > if given == 4:> > area=raw_input("Enter Area:")> > radius=(area/3.14)> >> > This is the whole program so far, because I haven't quite finished it yet.> > But I tried to get it to display another list of options after you select a> > shape but it just does this.> >> > Pick a shape:> > 1 Circle> > 2 Square> > 3 Triangle> > >1> > >1> > >>>> >> > I'm not sure why it does that but I do know that it is skipping the second> > list of options.> >> > Another of my problems is that I can't figure out how to get it to accept> > two different inputs for a selection. Like I want it to accept both the> > number 1 and circle as circle then list the options for circle. It won't> > even accept words. I can only get it to accept numbers. It's quite> > frustrating actually.> >> > Any advice would be greatly appreciated.> > Thanks in advance,> > Adam> >> >> >> >> >> > I tried to get it to display ano> >> > ________________________________> > Add some color. Personalize your inbox with your favorite colors. Try it!> > _______________________________________________> > Tutor maillist - Tutor at python.org> > http://mail.python.org/mailman/listinfo/tutor> >> >> > > -- > Andre Engels, andreengels at gmail.com> ICQ: 6260644 -- Skype: a_engels
_________________________________________________________________
Add some color. Personalize your inbox with your favorite colors.
www.windowslive-hotmail.com/learnmore/personalize.html?locale=en-us&ocid=TXT_TAGLM_HMWL_reten_addcolor_0507
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070523/9352e0f2/attachment.html
More information about the Tutor
mailing list