[Tutor] (no subject)
Hi,I just started python today and I would like a few pointers, if you don't mind. I tried using a tutorial, but was only able to get the correct results for the most basic problems. # Area calculation programprint “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 user’s choice:shape = input(“> “)# Calculate the area:if shape == 1:height = input(“Please enter the height: “)width = input(“Please enter the width: “) area = height*widthprint “The area is”, areaelse:radius = input(“Please enter the radius: “)area = 3.14*(radius**2)print “The area is”, areaI've been trying to get this to work. I was on a forum on Google and they said to put:input("press ENTER to continue")at the end. I did, but it didn't work. It runs the program but just shuts itself off when its done and i don't even get to select any of the option things that i'm supposed to be able to select. It just turns on then back off and I don't even get to see anything. Could someone help me out.ThanksAdam _ 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___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] trouble with "if"
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:", diameterprint "Circumference:", circumferenceprint "Area:", areaif given == 2: diameter=raw_input("Enter Diameter:")radius=(diameter/2) circumference=(diameter*3.14)area=(radius**2*3.14)print "Radius:", radiusprint "Circumference:", circumferenceprint "Area:", areaif 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:", diameterprint "Area:", areaif 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 Circle2 Square3 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,AdamI tried to get it to display ano _ 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___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] two input acceptions
Sorry, Hotmail doesn't have a turn of HTML feature or if it does, I couldn't find it. I think I'm just going to take your word for it that raw_input is better because I find the entire concept quite confusing. I tried typing in your example in IDLE and it didn't do anything, except:>>>>>>And then it told me that it didn't know what the >>("LOL") was. It really disliked the >> bit. I understand the concept though, I think. I have been using the raw_input though. If I change it from var=raw_input()>>("LOL")to var=raw_input("LOL")then it displays>>>LOL>>>Not sure what that means, but yeah. Well thanks anyway.Adam> Date: Sat, 19 May 2007 01:47:51 +0100> From: [EMAIL PROTECTED]> To: [EMAIL PROTECTED]; tutor@python.org> Subject: Re: [Tutor] two input acceptions> > adam urbas escreveu:> > Thanks for the help. I've made quite some progress since I first posted this email. I have a question though, what did you mean when you were talking about the raw_input( )? How can the regular input( ) be used evilly? If you could explain in depth, I would be very grateful. I have a new question related to my program area.py., I guess it's the same one as before. When I run the program and input the rectangle option, it asks me for a radius, unless I input 1, instead of rectangle. How do I program it to accept both 1 and rectangle?> Date: Sat, 12 May 2007 18:55:20 +0100> From: [EMAIL PROTECTED]> To: [EMAIL PROTECTED]> CC: tutor@python.org> Subject: Re: [Tutor] (no subject)> > adam urbas escreveu:> > Hi,I just started python today and I would like a few pointers, if you don't mind. I tried using a tutorial, but was only able to get the correct results for the most basic problems. # Area calculation programprint “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 user’s choice:shape = input(“> “)# Calculate the area:if shape == 1:height = input(“Please enter the height: “)width = input(“Please enter the width: “) area = height*widthprint “The area is”, areaelse:radius = input(“Please enter the radius: “)area = 3.14*(radius**2)print “The area is”, areaI've been trying to get this to work. I was on a forum on Google and they said to put:input("press ENTER to continue")at the end. I did, but it didn't work. It runs the program but just shuts itself off when its done and i don't even get to select any of the option things that i'm s> upposed to be able to select. It just turns on then back off and I don't even get to see anything. Could someone help me out.ThanksAdam> > _> > Create the ultimate e-mail address book. Import your cont> acts to Windows Live Hotmail.> > www.windowslive-hotmail.com/learnmore/managemail2.html?locale=en-us&ocid=TXT_TAGLM_HMWL_reten_impcont_0507> > > > > > > > > > ___> > Tutor maillist - Tutor@python.org> > http://mail.python.org/mailman/listinfo/tutor> > First, welcome to the world of Python. :D> Second. please give a title when you start a new thread on a mailing list.> Third, format your posts and code. Since Python uses indented code, it's > kinda hard to read it when it's all in one line (Don't worry, I'll paste > it indented in a file attached to this email :D )> > Now for the code.> > After arranging the code, the first thing I noticed were this characters “ ”> > I tried running the code, and if gave me a error there, so I just > replace then with " ", and voilá, the code worked :D . So the lesson > here is always use either " " or ' ' in the code.> > Oh, a> lso another thing. Don't use input() to get the user input, because > that command can run code and it may be evilly used. Always use > raw_input() instead :D .> > Anyway, I hope I helped you,> > > -- > _> ASCII ribbon campaign ( )> - against HTML email X> & vCards / \> > _> > 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> > First of all, what email client are you using?> Because the text is getting all weird and difficult to read (it's all
Re: [Tutor] two input acceptions
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
Re: [Tutor] trouble with "if"
Sorry, I forgot to attach the files. Don't critique too much. If you find a mistake in the program, then I probably haven't gotten that far, since it isn't complete yet. I'm pretty much on the editing phase now.> Date: Wed, 23 May 2007 18:08:20 +0200> From: [EMAIL PROTECTED]> To: [EMAIL PROTECTED]> Subject: Re: [Tutor] trouble with "if"> CC: tutor@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 <[EMAIL PROTECTED]>:> >> > 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!> > __
Re: [Tutor] trouble with "if"
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: [EMAIL PROTECTED]> To: [EMAIL PROTECTED]> Subject: Re: [Tutor] trouble with "if"> CC: tutor@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 <[EMAIL PROTECTED]>:> >> > 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@python.org> > http://mail.python.org/mailman/listinfo/tutor> >> >> > > -- > Andre Engels, [EMAIL PROTECTED]> 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___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] trouble with "if"
Sorry, I don't think Hotmail has turn off HTML. If it does I havn't been able to find it. I think you're going to have to explain your little bit of text stuff down there at the bottom. I have no idea what most of that means. All my choice things are working now though. I think that is what you were trying to help me with. What I used wasif shape in["1","circle"]:and if shape == "1" or shape =="circle":It works perfectly fine now.Ya that little bit o' code is really puzzling. I wish I knew more about this python deal. I understand the concept, but not the rules or the techniques and things of that sort. OK... I've got it... the data=raw_input('Feed Me!'). Ok I now understand that bit. Then it says Feed Me! and you put 42 (the ultimate answer to life the universe, everything). OK, it won't accept the bit. it doesn't like the "<". Well, I just removed that bit and it said:Feed Me! and I put 42, and it said >>> (I guess it's satisfied now, with the whole feeding). Well if I understood what 'str' meant, then I could probably figure the rest out. Well I have to go do other things so I'll save the rest of this figuring out till later.I shall return,Adam> Date: Wed, 23 May 2007 12:12:16 -0400> From: [EMAIL PROTECTED]> To: [EMAIL PROTECTED]> CC: tutor@python.org> Subject: Re: [Tutor] trouble with "if"> > adam urbas said unto the world upon 05/23/2007 11:57 AM:> > > > 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 t
[Tutor] error message questions
Hello all,I was wondering if there would be someone who would be able to give me a list of error messages and their meanings. I've attached this test.py to illustrate my problem. When I run the program, I am able to enter all the data, yet it will not calculate.It says:can't multiply sequence by non-int of type 'str'I really would like to know how to fix this.I get a similar message with my other one, radiacir.py:can't multiply sequence by non-int of type 'float'Please help!Thanks in advance,Adam _ Change is good. See what’s different about Windows Live Hotmail. http://www.windowslive-hotmail.com/learnmore/default.html?locale=en-us&ocid=RMT_TAGLM_HMWL_reten_changegood_0507 height=raw_input("enter height:") width=raw_input("enter width:") area=(height*width) print "area:",area #"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" or shape == "circle": 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 in["1", "radius"]: radius=raw_input("Enter Radius:") pi=3.14 diameter=(radius*2) circumference=(radius*2*pi) 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) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] trouble with "if"
Thank you for the help Brian. I would like to ask you about these things. Which one of the examples you gave would be most fool proof.> Date: Wed, 23 May 2007 13:40:09 -0400> From: [EMAIL PROTECTED]> To: [EMAIL PROTECTED]> CC: tutor@python.org> Subject: Re: [Tutor] trouble with "if"> > adam urbas said unto the world upon 05/23/2007 01:04 PM:> > Sorry, I don't think Hotmail has turn off HTML. If it does I> > havn't been able to find it. I think you're going to have to> > explain your little bit of text stuff down there at the bottom. I> > have no idea what most of that means. All my choice things are> > working now though. I think that is what you were trying to help> > me with. What I used wasif shape in["1","circle"]:and if shape ==> > "1" or shape =="circle":It works perfectly fine now.Ya that little> > bit o' code is really puzzling. I wish I knew more about this> > python deal. I understand the concept, but not the rules or the> > techniques and things of that sort. OK... I've got it... the> > data=raw_input('Feed Me!'). Ok I now understand that bit. Then it> > says Feed Me! and you put 42 (the ultimate answer to life the> > universe, everything). OK, it won't accept the bit.> > it doesn't like the "<". Well, I just removed that bit and it> > said:Feed Me! and I put 42, and it said >>> (I guess it's> > satisfied now, with the whole feeding). Well if I understood what> > 'str' meant, then I could probably figure the rest out. Well I> > have to go do other things so I'll save the rest of this figuring> > out till later.I shall return,Adam> Date: Wed, 23 May 2007 12:12:16> > -0400> From: [EMAIL PROTECTED]> To: [EMAIL PROTECTED]> CC:> > tutor@python.org> Subject: Re: [Tutor] trouble with "if"> > adam> > urbas said unto the world upon 05/23/2007 11:57 AM:> > > > 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(&
Re: [Tutor] trouble with indents
Thanks for the clarification, but I'm still a tad confused. I'm not sure when to indent. I understand that it has to be done. That link was really confusing. Very newb non-friendly. Arrg... That site is doom. So confusing. I need somewhere to start from the beginning. This site uses all kinds of big words and doesn't explain things in a clear manner. Oh well. Thanks for the help, though.Au> From: [EMAIL PROTECTED]> To: tutor@python.org> Date: Thu, 24 May 2007 15:30:34 -0400> Subject: Re: [Tutor] trouble with if> > >I'm not sure what the whole indentation thing is for. And now I'm having > >trouble with the if statement things.> > Maybe your if statement troubles have been solved by others by now, but I'll > just add that "the indentation thing" is a vital feature of Python, it is > the way to separate code blocks. Other languages uses other means, like > curly braces, etc. I get the sense those who like Python enjoy indentation > because it forces the code to be quite readable, and I agree. See this:> > http://www.diveintopython.org/getting_to_know_python/indenting_code.html> > Also, as mentioned previously, keep in mind that 2 is not the same as "2" > and "=" is not the same as "==". The single "=" is used to assign names to > objects, whereas the == is for evaluating something, so for if statements > use == and not =. Also note you can put "and" along with if, so you can say> > if x == "mom" and y == "dad":> print "my parents"> > and lots of other stuff.> -Che> > _> PC Magazine’s 2007 editors’ choice for best Web mail—award-winning Windows > Live Hotmail. > http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_pcmag_0507> _ 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___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] trouble with "if"
You don't know what a Ti 83 is. Calculator. The most basic programming available. It already has so many functions built into it that it is much easier to tell it to do things. You don't have to do all this integer conversion and such whatnot. Wow... I'm really unsure of how this thing is supposed to work. It seems the more I learn about Python, the more confused I become. It's enough to bring tears to your eyes. Not really but ya.Someone else helped me with the problem of accepting numbers and words. I used:if shape in["1","circle"]:something like that. It works wonderfully. I'm not sure why, but I know that it does and that is enough. Someone else also said that I had to convert to int, and I did. That was another problem, which is now fixed.But, as usual, it is just one problem after another. Now I have run into this error message: Traceback (most recent call last): File "C:\Documents and Settings\HP_Owner\Python0\area.py", line 23, in area = 3.14*(radius**2)TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'>>> and others like this:Traceback (most recent call last): File "C:\Documents and Settings\HP_Owner\Python0\area.py", line 19, in area = height*widthTypeError: can't multiply sequence by non-int of type 'str'>>> Very frustrating. What is a non-int and what is 'str'? Why can't it multiply the sequence? I guess I should include the program I'm using for these things.I'm having this problem with both of these attached. The messages above are from area.py. area.py is sort of a prototype of radiacir.py, a test version. You know, I should probably try that int trick, which I seem to have forgotten. And guess what that did it. It's amazing when you apply the things that you learn. Apparently I am quite absent minded. Well It seems I don't need any of this help anymore. Oh well. Thanks anyway.Au > To: tutor@python.org> From: [EMAIL PROTECTED]> Date: Thu, 24 May 2007 23:34:05 +0100> Subject: Re: [Tutor] trouble with "if"> > "adam urbas" <[EMAIL PROTECTED]> wrote > > > It won't even accept words. > > I can only get it to accept numbers. > > try this(untested code!):> > number = None> data = raw_input('Type something: ')> try: number = int(data)> except: data = data.split()# assume a string> > if number:# user entered a number> if number == 1: print 'circle'> elif number == 2: print 'another'> else: # user entered words> if data[0].lower() == 'circle': print 'circle'> else: print 'user entered ', data[0]> > Notice that to use ithe input as a number you have to > convert the raw input characters to a number (using int)> To get the individual words we can use split() which by > default splits a string into the individual words.> > Is that the kind of thing you mean?> > I've no idea what a Ti83 is BTW. :-)> > 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 = raw_input("> ") #"Calculate the area:" if shape in["1","rectangle"]: height = raw_input("Please enter the height: ") width = raw_input("Please enter the width: ") area = height*width print "The area is", area if shape in["2","circle"]: radius = raw_input("Please enter the radius: ") area = 3.14*(radius**2) print "The area is", area #"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" or shape == "circle": print "Choose the
Re: [Tutor] trouble with "if"
I thank you much Alan. This has been very helpful already and I'm only on page 2. The world needs more newb-friendly people like you.> To: tutor@python.org> From: [EMAIL PROTECTED]> Date: Thu, 24 May 2007 23:39:41 +0100> Subject: Re: [Tutor] trouble with "if"> > Hi adam. > > With the aid of Google it seems a Ti83 is a programmable calculator.> > I'm not sure what python tutor you are using but it looks like > you need to cover some very basic stuff around data types.> > You may find the Raw Materials topic in my tutor useful to give > you a feel for the different types of data in Python.> > The Talking to the User topic will cover the use of raw_input.> > And the Branching topic has an examplre very similar to what > you are trying to do.> > HTH,> > -- > Alan Gauld> Author of the Learn to Program web site> http://www.freenetpages.co.uk/hp/alan.gauld> > ___> Tutor maillist - Tutor@python.org> http://mail.python.org/mailman/listinfo/tutor _ Download Messenger. Start an i’m conversation. Support a cause. Join now. http://im.live.com/messenger/im/home/?source=TAGWL_MAY07___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] square root
Hi all,I was just wondering how I would go about performing a square root thing, for my radiacir.py program. _ Change is good. See what’s different about Windows Live Hotmail. www.windowslive-hotmail.com/learnmore/default.html?locale=en-us&ocid=TXT_TAGLM_HMWL_reten_changegood_0507___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] gmail
Hey, I have gmail now, but I'm not sure how to turn off HTML. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] trouble with "if"
The scary part is, I think I understand this. I copied your last example and put it in IDLE and it doesn't like you code. Never mind. I figured it out. So that is so it will notify you if your choice is invalid. Nice lil tidbit of information there. I'll be sure to use this. Oh and while your here, I'd like to ask about loops I guess they are. I want to have the program go back to the part where it asks for the user to select an option after it has run one of its if statements.Like, when the user tells it, "circle," then "radius," then enters the radius: here I would like the program to go back and ask the user if they want to do anything else, like find the area of a square, instead of the circle. Would I have to tell python to print all those selections again, or would there be a way to just return to the beginning?Thanks,Au> Date: Sun, 27 May 2007 15:10:08 -0400> From: [EMAIL PROTECTED]> To: [EMAIL PROTECTED]> CC: tutor@python.org> Subject: Re: [Tutor] trouble with "if"> > adam urbas said unto the world upon 05/27/2007 01:49 PM:> > Thank you for the help Brian. I would like to ask you about these> > things. Which one of the examples you gave would be most fool> > proof.> > readable>> > > Hi Adam and all,> > Adam was asking about how to use raw_input to drive a basic command > prompt menu system. I'd tried to explain that raw_input returns > strings, so his if tests which were something like:> > choice = raw_input("Enter an option)> if choice == 1:> do_option_1_stuff()> elif choice == 2:> do_option_2_stuff()> > were not going to work, as choice will never be equal to an int.> > I'd sketched a few ways to deal with this, chiefly applying int() to > choice or comparing choice to '1', etc.> > That's more of less the gist of the above snippage and takes us more > or less up to the point where Adam asked his question above.> > I'm going to show you a few things that might be new to you, Adam. > Let's build up in steps.> > As a first pass, I would do the following:> > choice = int(raw_input("Please make your choice "))> > if choice == 1:> # Option 1 code here> print "In option 1"> > elif choice == 2:> # Option 2 code here> print "In option 2"> > # Carry on if-test as needed (or until you get to the point> # of learning about dictionary dispatch :-)> > That will be fine, until your user enters something silly:> > >>>> Please make your choice I like bikes!> Traceback (most recent call last):>File "/home/brian/docs/jotter/python_scraps/adamcode.py", line 1, > in > choice = int(raw_input("Please make your choice "))> ValueError: invalid literal for int() with base 10: 'I like bikes!'> >>>> > That's no good!> > So, we can use Python's exception handling tools to make this a bit > better.> > > try:> choice = int(raw_input("Please make your choice "))> except ValueError:> print "Please make a choice from the options offered."> > > if choice == 1:> print "In option 1"> > elif choice == 2:> print "In option 2"> > > There is still a problem, though:> > >>> # Make sure the previous value assigned to choice is gone.> >>> del(choice)> >>>> Please make your choice I like Bikes> Please make a choice from the options offered.> Traceback (most recent call last):>File "/home/brian/docs/jotter/python_scraps/adamcode.py", line 7, > in > if choice == 1:> NameError: name 'choice' is not defined> >>>> > We've printed the reminder to the user, but then have gone on to > compare the non-existent choice value to 1, and that doesn't work so > well. It isn't enough to make sure that choice isn't insane---we need > to make sure that there is a choice value at all.> > So, better still:> > > while True:> try:> choice = int(raw_input("Please make your choice "))> # If the previous line worked, end the while loop. If it did> # not work, we won't get here, so the loop will keep looping.> break> except ValueError:> print "Please make a choice from the options offered."> > if choice == 1:> print "In option 1"> > elif choice == 2:> print "In option 2"> > > Now we get the following:> > Please make your choice I like bikes!> Please make a
Re: [Tutor] gmail
Ok, I'm not sure if I'm in the right gmail. When I type I don't see any buttons that say rich text or plain text. Only Send, Save Draft, and Discard. And I have no idea what jim is talking about. Please clarify. On 5/29/07, jim stockford <[EMAIL PROTECTED]> wrote: > > i'd be curious to see what happens if you > use the tag around your (properly) > indented code, e.g. > > > this = 1 > that = 0 > if this == 1 : > that = 1 > print that > > > > > On May 29, 2007, at 9:24 AM, Adam Urbas wrote: > > > Hey, > > > > I have gmail now, but I'm not sure how to turn off HTML. > > ___ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] trouble with "if"
ok well, I'm testing to see if the CC thing worked. On 5/29/07, Adam Urbas <[EMAIL PROTECTED]> wrote: > I'll try the CC thing. > > On 5/29/07, Adam Urbas <[EMAIL PROTECTED]> wrote: > > Well, Brian, I am now very sure that we have different versions of > > gmail, because on both the Quick Reply and the full reply screens, > > there are no Reply buttons, or downpointing arrows. > > > > On 5/29/07, Adam Urbas <[EMAIL PROTECTED]> wrote: > > > What is the actual command to exit the program. I tried exit, which > > > turned purple, so I know that does something. > > > > > > On 5/29/07, Adam Urbas <[EMAIL PROTECTED]> wrote: > > > > No I don't think that worked either, because now it has a problem with > > > > print. > > > > > > > > Please help. > > > > > > > > Au > > > > > > > > On 5/29/07, Adam Urbas <[EMAIL PROTECTED]> wrote: > > > > > I'm having trouble with the parentheses after the def thing(). IDLE > > > > > says that there is something wrong with it. If I type something > > > > > between them, it says that there is something wrong with the > quotation > > > > > marks. If I just leave it like (), then it says that something is > > > > > wrong with what is after the parentheses. Unless my code is > supposed > > > > > to go between the parentheses. I'll try that. > > > > > > > > > > On 5/29/07, Adam Urbas <[EMAIL PROTECTED]> wrote: > > > > > > In the def welcome(), what do you put in the parentheses? Another > > > > > > question, what code do you use for ending the program. I want the > > > > > > user to be able to cancel the program from the main menu, where it > > > > > > asks you to choose circle, square, etc. Or even perhaps allow the > > > > > > user to go back to a previous menu, well I suppose that would be > the > > > > > > def thing() code. But what if they were at the part where the > > program > > > > > > was asking them to input the radius, how would I give them the > > option > > > > > > of returning to the list of given measurements of a circle? > > > > > > > > > > > > On 5/29/07, Brian van den Broek <[EMAIL PROTECTED]> wrote: > > > > > > > adam urbas said unto the world upon 05/29/2007 12:39 PM: > > > > > > > > The scary part is, I think I understand this. I copied your > > last > > > > > > > > example and put it in IDLE and it doesn't like you code. > Never > > > > > > > > mind. I figured it out. So that is so it will notify you if > > your > > > > > > > > choice is invalid. Nice lil tidbit of information there. > I'll > > be > > > > > > > > sure to use this. Oh and while your here, I'd like to ask > about > > > > > > > > loops I guess they are. I want to have the program go back to > > the > > > > > > > > part where it asks for the user to select an option after it > has > > > > > > > > run one of its if statements.Like, when the user tells it, > > > > > > > > "circle," then "radius," then enters the radius: here I would > > like > > > > > > > > the program to go back and ask the user if they want to do > > > anything > > > > > > > > else, like find the area of a square, instead of the circle. > > > Would > > > > > > > > I have to tell python to print all those selections again, or > > > would > > > > > > > > there be a way to just return to the beginning?Thanks,Au> > Date: > > > > > > > > > > > > > > > > > > > > > Hi Adam, > > > > > > > > > > > > > > Again, I cut the mess, but I expect that if you use the gmail > > > account > > > > > > > you just posted about here on in, that will be the end of it. > > > > > > > > > > > > > > I'm glad that you are starting to have the warm glow of > > > understanding > > > > > :-) > > > > > > > > > > > > > > What you are asking about here is one reason why functions are > so > > > > > > >
Re: [Tutor] trouble with "if"
Dang it... I am really going to have to figure out how to reply all. The cc thing only worked once and now I'm still sending to you. On 5/30/07, Adam Urbas <[EMAIL PROTECTED]> wrote: > I started to read Alan Gauld's tutorial. The problem is, once I get > past the very basics of something, I tend to get impatient and don't > want to go back and have to redo them, but the other problem is, I may > need something that is taught in the basic sections. So ya, I'll try > to keep on a reading Alan's tutorial. > > On 5/30/07, Adam Urbas <[EMAIL PROTECTED]> wrote: > > I have already subscribed. I tried sending a message when I was not > > yet subscribed, and the Moderator or Administrator, or whoever said to > > resubscribe. Sorry about my accident programming. > > > > On 5/29/07, Adam Urbas <[EMAIL PROTECTED]> wrote: > > > ok well, I'm testing to see if the CC thing worked. > > > > > > On 5/29/07, Adam Urbas <[EMAIL PROTECTED]> wrote: > > > > I'll try the CC thing. > > > > > > > > On 5/29/07, Adam Urbas <[EMAIL PROTECTED]> wrote: > > > > > Well, Brian, I am now very sure that we have different versions of > > > > > gmail, because on both the Quick Reply and the full reply screens, > > > > > there are no Reply buttons, or downpointing arrows. > > > > > > > > > > On 5/29/07, Adam Urbas <[EMAIL PROTECTED]> wrote: > > > > > > What is the actual command to exit the program. I tried exit, > which > > > > > > turned purple, so I know that does something. > > > > > > > > > > > > On 5/29/07, Adam Urbas <[EMAIL PROTECTED]> wrote: > > > > > > > No I don't think that worked either, because now it has a > problem > > > with > > > > > > > print. > > > > > > > > > > > > > > Please help. > > > > > > > > > > > > > > Au > > > > > > > > > > > > > > On 5/29/07, Adam Urbas <[EMAIL PROTECTED]> wrote: > > > > > > > > I'm having trouble with the parentheses after the def thing(). > > > IDLE > > > > > > > > says that there is something wrong with it. If I type > something > > > > > > > > between them, it says that there is something wrong with the > > > > quotation > > > > > > > > marks. If I just leave it like (), then it says that > something > > is > > > > > > > > wrong with what is after the parentheses. Unless my code is > > > > supposed > > > > > > > > to go between the parentheses. I'll try that. > > > > > > > > > > > > > > > > On 5/29/07, Adam Urbas <[EMAIL PROTECTED]> wrote: > > > > > > > > > In the def welcome(), what do you put in the parentheses? > > > Another > > > > > > > > > question, what code do you use for ending the program. I > want > > > the > > > > > > > > > user to be able to cancel the program from the main menu, > > where > > > it > > > > > > > > > asks you to choose circle, square, etc. Or even perhaps > allow > > > the > > > > > > > > > user to go back to a previous menu, well I suppose that > would > > be > > > > the > > > > > > > > > def thing() code. But what if they were at the part where > the > > > > > program > > > > > > > > > was asking them to input the radius, how would I give them > the > > > > > option > > > > > > > > > of returning to the list of given measurements of a circle? > > > > > > > > > > > > > > > > > > On 5/29/07, Brian van den Broek <[EMAIL PROTECTED]> > wrote: > > > > > > > > > > adam urbas said unto the world upon 05/29/2007 12:39 PM: > > > > > > > > > > > The scary part is, I think I understand this. I copied > > your > > > > > last > > > > > > > > > > > example and put it in IDLE and it doesn't like you code. > > > > Never > > > > > > > > > > > mind. I figured it out. So that is so it will notify > you > > > if > > > > > yo
Re: [Tutor] [Fwd: Re: trouble with "if"]
I can't exactly show you the error message anymore, because the program is now screwed up in so many ways that I can't even get it to do the things it used to. It says things like ERROR: Inconsistent indentation detected! 1) Your indentation is outright incorrect (easy to fix), OR 2) Your indentation mixes tabs and spaces. Then it tells me to untabify everything, which i did and it still gives this message. I've started completely over with the exact same indentation and that one works. Oh my gosh this gmail is a fricken crack head... none of this stuff was here last night. I have no idea what was going on then, but everything you guys said is right here. The plain text is right next to the Check spelling, the reply to all is right above send and save now and in the corner near the little arrow. Well, it's working now. Ok, so if i have a section of code that is: answer=(2+3): print "answer", answer so for the code above I would put: (I think I would have to have the two numbers and the addition thing in there wouldn't I; I saw something like this on Alan's tutorial last night.) def answer(2,3): answer=(2+3) print "answer",answer That is obviously not right.: There's an error in your program: invalid syntax when it says that it highlights the 2: def answer(2+3): Ok I think I understand these now. Thanks for the advice. I have this now: def answer(): print("answer") answer() It works too, yay! Thanks, Au On 5/30/07, Andre Engels <[EMAIL PROTECTED]> wrote: 2007/5/30, Brian van den Broek <[EMAIL PROTECTED]>: > Another fwd, folks. > > Brian vdB > > Original Message ---- > Subject: Re: [Tutor] trouble with "if" > Date: Tue, 29 May 2007 23:28:46 -0500 > From: Adam Urbas <[EMAIL PROTECTED]> > To: Brian van den Broek <[EMAIL PROTECTED]> > References: <[EMAIL PROTECTED]> > <[EMAIL PROTECTED]> > <[EMAIL PROTECTED]> > > I'm having trouble with the parentheses after the def thing(). IDLE > says that there is something wrong with it. If I type something > between them, it says that there is something wrong with the quotation > marks. If I just leave it like (), then it says that something is > wrong with what is after the parentheses. Unless my code is supposed > to go between the parentheses. I'll try that. Between the parentheses should go the variables you use (if any) when calling the function. For example: def sayhello(): print "Hello" You don't have any parameters here, so there's nothing between the brackets def say(word): print word Now there is one parameter, namely word. def sayboth(word1,word2): print word1 print word2 Here there are two parameters, word1 and word2. The number of parameters should be the same as the number of parameters you use when calling the function: sayhello() say("One text") sayboth("One text","Another text") There is a much used method to make some of the parameters optional, but we'll not go into that. To know what is going wrong with your program, I would have to see the program (or a simplified version of it that still goes wrong) and preferably also the exact error message you are getting. -- Andre Engels, [EMAIL PROTECTED] ICQ: 6260644 -- Skype: a_engels ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [Fwd: Re: trouble with "if"]
Ahahahahaha... I have figured these out beyond comprehension and power. Wahhaha. It feels good to get something to work correctly. Thanks much Andre. I don't quite understand the putting of things inside the parentheses, but I've discovered that I don't really need to, because def text(): works just fine with everything I've done so far. On 5/30/07, Adam Urbas <[EMAIL PROTECTED]> wrote: I can't exactly show you the error message anymore, because the program is now screwed up in so many ways that I can't even get it to do the things it used to. It says things like ERROR: Inconsistent indentation detected! 1) Your indentation is outright incorrect (easy to fix), OR 2) Your indentation mixes tabs and spaces. Then it tells me to untabify everything, which i did and it still gives this message. I've started completely over with the exact same indentation and that one works. Oh my gosh this gmail is a fricken crack head... none of this stuff was here last night. I have no idea what was going on then, but everything you guys said is right here. The plain text is right next to the Check spelling, the reply to all is right above send and save now and in the corner near the little arrow. Well, it's working now. Ok, so if i have a section of code that is: answer=(2+3): print "answer", answer so for the code above I would put: (I think I would have to have the two numbers and the addition thing in there wouldn't I; I saw something like this on Alan's tutorial last night.) def answer(2,3): answer=(2+3) print "answer",answer That is obviously not right.: There's an error in your program: invalid syntax when it says that it highlights the 2: def answer( 2+3): Ok I think I understand these now. Thanks for the advice. I have this now: def answer(): print("answer") answer() It works too, yay! Thanks, Au On 5/30/07, Andre Engels <[EMAIL PROTECTED] > wrote: > > 2007/5/30, Brian van den Broek < [EMAIL PROTECTED]>: > > Another fwd, folks. > > > > Brian vdB > > > > ---- Original Message > > Subject: Re: [Tutor] trouble with "if" > > Date: Tue, 29 May 2007 23:28:46 -0500 > > From: Adam Urbas <[EMAIL PROTECTED]> > > To: Brian van den Broek <[EMAIL PROTECTED]> > > References: < [EMAIL PROTECTED]> > > <[EMAIL PROTECTED]> > > < [EMAIL PROTECTED]> > > > > I'm having trouble with the parentheses after the def thing(). IDLE > > says that there is something wrong with it. If I type something > > between them, it says that there is something wrong with the quotation > > marks. If I just leave it like (), then it says that something is > > wrong with what is after the parentheses. Unless my code is supposed > > to go between the parentheses. I'll try that. > > Between the parentheses should go the variables you use (if any) when > calling the function. For example: > > def sayhello(): > print "Hello" > > You don't have any parameters here, so there's nothing between the > brackets > > def say(word): > print word > > Now there is one parameter, namely word. > > def sayboth(word1,word2): > print word1 > print word2 > > Here there are two parameters, word1 and word2. > > The number of parameters should be the same as the number of > parameters you use when calling the function: > > sayhello() > say("One text") > sayboth("One text","Another text") > > There is a much used method to make some of the parameters optional, > but we'll not go into that. > > To know what is going wrong with your program, I would have to see the > program (or a simplified version of it that still goes wrong) and > preferably also the exact error message you are getting. > > > -- > Andre Engels, [EMAIL PROTECTED] > ICQ: 6260644 -- Skype: a_engels > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [Fwd: Re: trouble with "if"]
I can't seem to get the type with the parameters to work. I can get def answer(): to work, but not def answer(my_first_parameter,my_second_parameter):. I'm not too concerned, as I haven't yet needed to use that. But, when I use the parameter type, it runs without error messages, but doesn't display anything. That's when I'm using your example with my_first_parameter. But when I use: def answer(40,2): answer=40+2 print "Answer:\t", value answer() it says: There's an error in your program: invalid syntax and then it highlights the first number between the parentheses, like last time. OK. New topic temporarily... I just completed a portion of my radiacir.py program, after much debugging. I still want to add that error message thing that we discussed eariler, but that's a whole nother can of worms. So I'm going to attach it. This is very exciting. Except, I renamed it and now it doesn't work. This frustrates me. How could something work one second and then not the next. Oh well, I'll still attach it and if you could help me find the problem, that would be nice. Thanks, Au On 5/30/07, Brian van den Broek <[EMAIL PROTECTED]> wrote: > Adam Urbas said unto the world upon 05/30/2007 11:01 AM: > > I can't exactly show you the error message anymore, because the program is > > now screwed up in so many ways that I can't even get it to do the things it > > used to. > > > > It says things like ERROR: Inconsistent indentation detected! > > 1) Your indentation is outright incorrect (easy to fix), OR > > 2) Your indentation mixes tabs and spaces. Then it tells me to untabify > > everything, which i did and it still gives this message. I've started > > completely over with the exact same indentation and that one works. > > > > Oh my gosh this gmail is a fricken crack head... none of this stuff was > > here > > last night. I have no idea what was going on then, but everything you guys > > said is right here. The plain text is right next to the Check spelling, > > the > > reply to all is right above send and save now and in the corner near the > > little arrow. Well, it's working now. > > > > Ok, so if i have a section of code that is: > > > > answer=(2+3): > > print "answer", answer > > > > so for the code above I would put: (I think I would have to have the two > > numbers and the addition thing in there wouldn't I; I saw something like > > this on Alan's tutorial last night.) > > > > def answer(2,3): > >answer=(2+3) > >print "answer",answer > > > > That is obviously not right.: > > > > There's an error in your program: > > invalid syntax > > > > when it says that it highlights the 2: def answer(2+3): > > > > Ok I think I understand these now. Thanks for the advice. I have this > > now: > > > > def answer(): > >print("answer") > > answer() > > > > It works too, yay! > > Thanks, > > > > Au > > > > > Adam, > > Glad you are sorting out the gmail---in the long run, plain text will > make this all much easier than what you had before :-) > > Your answer function definition above is saying something like this: > make answer the name of a function that takes no parameters, and, when > called, have it execute a print. > > This: > > > def answer(2,3): > >answer=(2+3) > >print "answer",answer > > doesn't work, as you are trying to set the values of the two > parameters to 2 and 3 in the function definition itself. That's not > how parameters work. The definition of a function sets the parameters > up as named `slots' that function calls will give values to. (There > are, as Andre pointed out, more details, but let those aside for now > and focus on the simplest cases.) > > This: > > def answer(): > answer=(2+3) > print "answer",answer > > would work, but it isn't much different than the code that did work. > > Try this: > > def answer(my_first_parameter, my_second_parameter): > value = my_first_parameter + my_second_parameter > print "Answer:\t", value > > (I wouldn't use the cumbersome names `my_first_parameter', etc. in > real code, but perhaps they help keeping track of what is going on in > early stages.) > > That says, in effect, let answer be a function which takes two > positional parameters, adds them, and prints the result in an > informative way. > > >>> answer(40, 2) > Answer: 42 > >>> answer("A string", " and another string") > Answer: A string and another string > >>> > > These work because the function definition ensures that the first > parameter (40, in the first case above) will, as far as the function > is concerned, be called my_first_parameter. (Likewise for 2 and > my_second_parameter.) > > Does that help? > > Brian vdB > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [Fwd: Re: trouble with "if"]
I think I may have figured it out. I just switched some things around. On 5/30/07, Adam Urbas <[EMAIL PROTECTED]> wrote: I can't seem to get the type with the parameters to work. I can get def answer(): to work, but not def answer(my_first_parameter,my_second_parameter):. I'm not too concerned, as I haven't yet needed to use that. But, when I use the parameter type, it runs without error messages, but doesn't display anything. That's when I'm using your example with my_first_parameter. But when I use: def answer(40,2): answer=40+2 print "Answer:\t", value answer() it says: There's an error in your program: invalid syntax and then it highlights the first number between the parentheses, like last time. OK. New topic temporarily... I just completed a portion of my radiacir.py program, after much debugging. I still want to add that error message thing that we discussed eariler, but that's a whole nother can of worms. So I'm going to attach it. This is very exciting. Except, I renamed it and now it doesn't work. This frustrates me. How could something work one second and then not the next. Oh well, I'll still attach it and if you could help me find the problem, that would be nice. Thanks, Au On 5/30/07, Brian van den Broek <[EMAIL PROTECTED]> wrote: > Adam Urbas said unto the world upon 05/30/2007 11:01 AM: > > I can't exactly show you the error message anymore, because the program is > > now screwed up in so many ways that I can't even get it to do the things it > > used to. > > > > It says things like ERROR: Inconsistent indentation detected! > > 1) Your indentation is outright incorrect (easy to fix), OR > > 2) Your indentation mixes tabs and spaces. Then it tells me to untabify > > everything, which i did and it still gives this message. I've started > > completely over with the exact same indentation and that one works. > > > > Oh my gosh this gmail is a fricken crack head... none of this stuff was > > here > > last night. I have no idea what was going on then, but everything you guys > > said is right here. The plain text is right next to the Check spelling, > > the > > reply to all is right above send and save now and in the corner near the > > little arrow. Well, it's working now. > > > > Ok, so if i have a section of code that is: > > > > answer=(2+3): > > print "answer", answer > > > > so for the code above I would put: (I think I would have to have the two > > numbers and the addition thing in there wouldn't I; I saw something like > > this on Alan's tutorial last night.) > > > > def answer(2,3): > >answer=(2+3) > >print "answer",answer > > > > That is obviously not right.: > > > > There's an error in your program: > > invalid syntax > > > > when it says that it highlights the 2: def answer(2+3): > > > > Ok I think I understand these now. Thanks for the advice. I have this > > now: > > > > def answer(): > >print("answer") > > answer() > > > > It works too, yay! > > Thanks, > > > > Au > > > > > Adam, > > Glad you are sorting out the gmail---in the long run, plain text will > make this all much easier than what you had before :-) > > Your answer function definition above is saying something like this: > make answer the name of a function that takes no parameters, and, when > called, have it execute a print. > > This: > > > def answer(2,3): > >answer=(2+3) > >print "answer",answer > > doesn't work, as you are trying to set the values of the two > parameters to 2 and 3 in the function definition itself. That's not > how parameters work. The definition of a function sets the parameters > up as named `slots' that function calls will give values to. (There > are, as Andre pointed out, more details, but let those aside for now > and focus on the simplest cases.) > > This: > > def answer(): > answer=(2+3) > print "answer",answer > > would work, but it isn't much different than the code that did work. > > Try this: > > def answer(my_first_parameter, my_second_parameter): > value = my_first_parameter + my_second_parameter > print "Answer:\t", value > > (I wouldn't use the cumbersome names `my_first_parameter', etc. in > real code, but perhaps they help keeping track of what is going on in > early stages.) > > That says, in effect, let answer be a function which takes two > positional parameters, ad
Re: [Tutor] [Fwd: Re: trouble with "if"]
Ok I forgot to put some things on the previous one. I discovered a flaw in my loop. It is not infinite. If you select circle, radius, enter the radius, circle, radius, enter the radius, then the program stops. I want it to be able to keep going as many times as needed, infinitely. So that the user could keep using that segment of the program over and over again, without having to restart the program. Is it possible to do that? On 5/30/07, Adam Urbas <[EMAIL PROTECTED]> wrote: I think I may have figured it out. I just switched some things around. On 5/30/07, Adam Urbas <[EMAIL PROTECTED]> wrote: > I can't seem to get the type with the parameters to work. I can get > def answer(): to work, but not def > answer(my_first_parameter,my_second_parameter):. I'm not too > concerned, as I haven't yet needed to use that. But, when I use the > parameter type, it runs without error messages, but doesn't display > anything. That's when I'm using your example with my_first_parameter. > But when I use: > > def answer(40,2): > answer=40+2 > print "Answer:\t", value > answer() > > it says: > > There's an error in your program: > invalid syntax > > and then it highlights the first number between the parentheses, like last time. > > OK. New topic temporarily... I just completed a portion of my > radiacir.py program, after much debugging. I still want to add that > error message thing that we discussed eariler, but that's a whole > nother can of worms. So I'm going to attach it. This is very > exciting. Except, I renamed it and now it doesn't work. This > frustrates me. How could something work one second and then not the > next. Oh well, I'll still attach it and if you could help me find the > problem, that would be nice. > > Thanks, > Au > On 5/30/07, Brian van den Broek <[EMAIL PROTECTED]> wrote: > > Adam Urbas said unto the world upon 05/30/2007 11:01 AM: > > > I can't exactly show you the error message anymore, because the program is > > > now screwed up in so many ways that I can't even get it to do the things it > > > used to. > > > > > > It says things like ERROR: Inconsistent indentation detected! > > > 1) Your indentation is outright incorrect (easy to fix), OR > > > 2) Your indentation mixes tabs and spaces. Then it tells me to untabify > > > everything, which i did and it still gives this message. I've started > > > completely over with the exact same indentation and that one works. > > > > > > Oh my gosh this gmail is a fricken crack head... none of this stuff was > > > here > > > last night. I have no idea what was going on then, but everything you guys > > > said is right here. The plain text is right next to the Check spelling, > > > the > > > reply to all is right above send and save now and in the corner near the > > > little arrow. Well, it's working now. > > > > > > Ok, so if i have a section of code that is: > > > > > > answer=(2+3): > > > print "answer", answer > > > > > > so for the code above I would put: (I think I would have to have the two > > > numbers and the addition thing in there wouldn't I; I saw something like > > > this on Alan's tutorial last night.) > > > > > > def answer(2,3): > > >answer=(2+3) > > >print "answer",answer > > > > > > That is obviously not right.: > > > > > > There's an error in your program: > > > invalid syntax > > > > > > when it says that it highlights the 2: def answer(2+3): > > > > > > Ok I think I understand these now. Thanks for the advice. I have this > > > now: > > > > > > def answer(): > > >print("answer") > > > answer() > > > > > > It works too, yay! > > > Thanks, > > > > > > Au > > > > > > > > > Adam, > > > > Glad you are sorting out the gmail---in the long run, plain text will > > make this all much easier than what you had before :-) > > > > Your answer function definition above is saying something like this: > > make answer the name of a function that takes no parameters, and, when > > called, have it execute a print. > > > > This: > > > > > def answer(2,3): > > >answer=(2+3) > > >print "answer",answer > > > > doesn't work, as you are trying to set the values of the two
Re: [Tutor] [Fwd: Re: trouble with "if"]
Once again this is my latest version. I know of several problems, such as the previously posted infinite looping problem. Also, if sends you to the wrong place sometimes. Ex: a second ago, I pressed 4 to exit (which does not work either) and it took me to triangle. I'm not sure how to end the program. It takes you to the def goodbye(): part, but then if you press enter again, it starts the program over. I was hoping that if I just left it blank, then it would just automatically end, like it does with simpler programs, but that was not the case, because apparently there has to be something after the def goodbye(): So If someone wouldn't mind taking a look at it, then I would be very grateful. Thanks, Au On 5/30/07, Adam Urbas <[EMAIL PROTECTED]> wrote: Ok I forgot to put some things on the previous one. I discovered a flaw in my loop. It is not infinite. If you select circle, radius, enter the radius, circle, radius, enter the radius, then the program stops. I want it to be able to keep going as many times as needed, infinitely. So that the user could keep using that segment of the program over and over again, without having to restart the program. Is it possible to do that? On 5/30/07, Adam Urbas <[EMAIL PROTECTED]> wrote: > I think I may have figured it out. I just switched some things around. > > On 5/30/07, Adam Urbas <[EMAIL PROTECTED]> wrote: > > I can't seem to get the type with the parameters to work. I can get > > def answer(): to work, but not def > > answer(my_first_parameter,my_second_parameter):. I'm not too > > concerned, as I haven't yet needed to use that. But, when I use the > > parameter type, it runs without error messages, but doesn't display > > anything. That's when I'm using your example with my_first_parameter. > > But when I use: > > > > def answer(40,2): > > answer=40+2 > > print "Answer:\t", value > > answer() > > > > it says: > > > > There's an error in your program: > > invalid syntax > > > > and then it highlights the first number between the parentheses, like last time. > > > > OK. New topic temporarily... I just completed a portion of my > > radiacir.py program, after much debugging. I still want to add that > > error message thing that we discussed eariler, but that's a whole > > nother can of worms. So I'm going to attach it. This is very > > exciting. Except, I renamed it and now it doesn't work. This > > frustrates me. How could something work one second and then not the > > next. Oh well, I'll still attach it and if you could help me find the > > problem, that would be nice. > > > > Thanks, > > Au > > On 5/30/07, Brian van den Broek <[EMAIL PROTECTED]> wrote: > > > Adam Urbas said unto the world upon 05/30/2007 11:01 AM: > > > > I can't exactly show you the error message anymore, because the program is > > > > now screwed up in so many ways that I can't even get it to do the things it > > > > used to. > > > > > > > > It says things like ERROR: Inconsistent indentation detected! > > > > 1) Your indentation is outright incorrect (easy to fix), OR > > > > 2) Your indentation mixes tabs and spaces. Then it tells me to untabify > > > > everything, which i did and it still gives this message. I've started > > > > completely over with the exact same indentation and that one works. > > > > > > > > Oh my gosh this gmail is a fricken crack head... none of this stuff was > > > > here > > > > last night. I have no idea what was going on then, but everything you guys > > > > said is right here. The plain text is right next to the Check spelling, > > > > the > > > > reply to all is right above send and save now and in the corner near the > > > > little arrow. Well, it's working now. > > > > > > > > Ok, so if i have a section of code that is: > > > > > > > > answer=(2+3): > > > > print "answer", answer > > > > > > > > so for the code above I would put: (I think I would have to have the two > > > > numbers and the addition thing in there wouldn't I; I saw something like > > > > this on Alan's tutorial last night.) > > > > > > > > def answer(2,3): > > > >answer=(2+3) > > > >print "answer",answer > > > > > > > > That is obviously not right.: > > > > > > > > There's an error
[Tutor] Calculator research
Sup all, Ok, this is my research for a better calculator. I want to make a calculator that is much less lame than the one that comes standard with windows. If anyone has any ideas for how to start or some things I should know, then feel free to inform me. The truth is, I don't exactly know where to start. I'm not yet though, I'm still working on that area calculation thing, which I intend to be a part of the calculator. Also, I'd like to know how to make my program have visual qualities, like the standard calculator. I assume that this is either impossible or very advanced/difficult, considering I have not previously heard anything about it. It doesn't have to be a visual display, though, just was wondering how to go about doing it and thought this might be the program to try it out on. Thanks, Au ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [Fwd: Re: trouble with "if"]
Sorry about all that trouble for you Alan, after I posted that, I reformatted my code a bit and updated it to do the defining and then the calling, like you said. The only problem I had, and I was probably doing something wrong, was that I would do: choice() if choice in["1","circle"]: circle() and it wouldn't actually go to circle(). So I had to put the if statement somewhere else, can't remember where it was right now and don't have time to find out, because I really need to be getting off of here. Thanks for the advice, and if you could, would you mind explaining the global variable thing a little more, because I kept getting an error message that was saying something to the effect that the global variable was not defined. Thanks, Au On 5/30/07, Alan Gauld <[EMAIL PROTECTED]> wrote: > Hi Adam > > > flaw in my loop. It is not infinite. > > In fact you don't have a loop, your program > is really just a simple sequence. > > #Welcome screen: > def welcome(): > print "Welcome to the Area Calculation Program." > print > > welcome() > > AG:Since you only call this once there is no point in putting > AG: it in a functuion > > #Shape choice: > def shape(): > print "Choose a Shape:" > print "1 Circle" > print "2 Square" > print "3 Triangle" > print "4 Exit" > print > > shape() > > AG: And you call this here and again at the end of the code. > AG: But its not in a loop, its just two calls to the same function. > > #If circle: > def circle(): > shape=raw_input(">") > if shape in["1","circle"]: > print "1 Radius" > print "2 Diameter" > print "3 Circumference" > print "4 Area" > print > > circle() > > AG: And this gets a string fom the user and prints one of the > AG: values but doesn't do anything with it. Functions should > AG: normally do more than just print some values. > AG: You never use the menu you print. > > #If radius: > def radius(): > radius=int(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 > print > print > > def choice(): > given=raw_input(">") > if given in["1","radius"]: > radius() > choice() > > AG: Now you call radius which actually does some work > > shape() > choice() > > AG: Then you call shape but don't use the result then call > AG: choice which only works for circles. > > AG:If we use the more conventional approach of defining the > AG: functins first then calling them at the end your code > AG: looks like this: > > > welcome() > shape() > circle() > choice() #--> which calls radius() > shape() > choice() > > As you see there is no loop just a sequence of function calls. > > Now if I rename your functions to reflect what theyactually do: > > printWelcomeMessage() > printShapeMenu() > getShapeAndIfCirclePrintCircleParameterNames() > getParameterAndIfRadiuscallRadius() > -> getRadiusCalculateResultsAndPrintThem() > printShapeMenu() > getParameterAndIfRadiuscallRadius() > -> getRadiusCalculateResultsAndPrintThem() > > Hopefully this illustrates several things: > 1) Naming your functions to reflect what they actually do > helps see what the code does > 2) Especially if you group the function calls together at the > end of your program > 3) Your functions are mixing up the presentation of menus > and the getting of values. > > A better structure might be to do something like: > > shape = 0 # a variable to store the shape > printWelcomeMessage() > printShapeMenuAndGetValue() #---store he result in the shape variable > if shape in['1','circle']: > doAllCircleStuff() > else: print "Only circles supported for now!" > > And then its easy to wrap that in a real loop > > shape = 0 # a variable to store the shape > printWelcomeMessage() > while shape == 0: >printShapeMenuAndGetValue() #---store he result in the shape > variable >if shape in['1','circle']: > doAllCircleStuff() > shape = 0 # reset shape back to zero >else: print "Only circles supported for now!" > > Can you rewrite your functions to match that? You need to change > the shape() function so that it sets the shape global variable to the > value input by the user. You will need to include the statement > global shape at the top of the function for that to work. The other > (and better) way is to use the return statement to return the value. > > BTW I'm not really suggesting you use those long names, > they were just to point out what the functions were really doing! > > HTH, > > Alan G. > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Calculator research
Ok then Alan, I'll be sure to check that out. I wasn't sure that what a GUI was so now I know. I haven't been able to mess around with python for a while, so I haven't gotten any further on your tutorial. The problem I had before was that I was really excited to create something original or better or ,you know, anything, that I wasn't really willing to just slow down and take the time to actually learn python. Something has changed since then. So I will probably not be messaging again for a while, because I'll be reading the tutorial. Thanks, Au On 6/2/07, Alan Gauld <[EMAIL PROTECTED]> wrote: > > "Adam Urbas" <[EMAIL PROTECTED]> wrote > > > Ok, this is my research for a better calculator. I want to make a > > calculator that is much less lame than the one that comes standard > > Thats a good beginners project. But you should go through > one of the tutorials first because you are still asking a lot of > very basic questions. A few hours going through the > rudimentary things will speed up your project a lot. > > > Also, I'd like to know how to make my program have visual qualities, > > like the standard calculator. > > I assume you want it to have a GUI fron end with buttons etc? > Yes thats possible and my tutorial includes a topic to get you > started plus some example programs. but it is a more advanced > topic that really requires you to know about OOP and event-driven > style programs first. > > > -- > Alan Gauld > Author of the Learn to Program web site > http://www.freenetpages.co.uk/hp/alan.gauld > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Correct use of range function..
I discovered something about your revers word program here. I used the "for c in word" one. if you type an indented print after print c, then it will print the words vertically. Just thought I'd share that with you. On 6/10/07, Kent Johnson <[EMAIL PROTECTED]> wrote: > David Hamilton wrote: > > I just finished doing an exercise in a tutorial on the range function > > and while I got it to work, my answer seems ugly. I'm wondering if I'm > > missing something in the way I'm using the range function. > > The tutorial ask me to print a string backwards. My solution works, but > > it it just doesn't "feel" right :). My result is difficult to read and > > I feel like I'm probably over complicating the solution. Suggestions? > > > > word="reverse" > > #Start at the end of the string, count back to the start, printing each > > letter > > for i in range(len(word)-1,-1,-1): > > print word[i], > > That's probably the best you can do using range(). You could write > ln = len(word) > for i in range(ln): >print word[ln-i-1], > > but that is not much different. > > You can do better without using range; you can directly iterate the > letters in reverse: > > for c in word[::-1]: >print c, > > Kent > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Correct use of range function..
I see... Very Intriguing.> To: tutor@python.org> From: [EMAIL PROTECTED]> Date: Sun, 10 Jun 2007 18:16:00 +0100> Subject: Re: [Tutor] Correct use of range function..> > > "Adam Urbas" <[EMAIL PROTECTED]> wrote> >I discovered something about your revers word program here. I used> > the "for c in word" one.> > if you type an indented print after print c, then it will print the> > words vertically. Just thought I'd share that with you.> > You can achieve the same by missing out the comma at the end> of the print statement too. The comma suppresses a newline> character. By using a second print you put it back! So just> missing the comma achieves the same end result.> > Alan G.> > > On 6/10/07, Kent Johnson <[EMAIL PROTECTED]> wrote:> >> David Hamilton wrote:> >> > I just finished doing an exercise in a tutorial on the range > >> > function> >> > and while I got it to work, my answer seems ugly. I'm wondering > >> > if I'm> >> > missing something in the way I'm using the range function.> >> > The tutorial ask me to print a string backwards. My solution > >> > works, but> >> > it it just doesn't "feel" right :). My result is difficult to > >> > read and> >> > I feel like I'm probably over complicating the solution. > >> > Suggestions?> >> >> >> > word="reverse"> >> > #Start at the end of the string, count back to the start, > >> > printing each> >> > letter> >> > for i in range(len(word)-1,-1,-1):> >> > print word[i],> >>> >> That's probably the best you can do using range(). You could write> >> ln = len(word)> >> for i in range(ln):> >>print word[ln-i-1],> >>> >> but that is not much different.> >>> >> You can do better without using range; you can directly iterate the> >> letters in reverse:> >>> >> for c in word[::-1]:> >>print c,> >>> >> Kent> >> ___> >> Tutor maillist - Tutor@python.org> >> http://mail.python.org/mailman/listinfo/tutor> >>> > ___> > Tutor maillist - Tutor@python.org> > http://mail.python.org/mailman/listinfo/tutor> > > > > ___> Tutor maillist - Tutor@python.org> http://mail.python.org/mailman/listinfo/tutor _ Hotmail to go? Get your Hotmail, news, sports and much more! Check out the New MSN Mobile! http://mobile.msn.com___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] easygui question, again
Where did you get this easygui thing you are trying to install. Is it the thing that says Compiled Python File? If so I have it. I've kinda been following your little chat here about it. I want to see if I could do it. On 6/11/07, Kent Johnson <[EMAIL PROTECTED]> wrote: > Alan Gauld wrote: > > "Rafael Bejarano" <[EMAIL PROTECTED]> wrote > > > >> that it would be a relatively simple matter to import the easygui > >> module and call its functions using the terminal window, especially > >> given that I have had success in the past importing other modules > >> and > >> calling their functions. > > > > I suspect that this is because you have been using > > the standard library modules which Python knows how to find. > > When you add a downloaded module, like easygui, you need > > to let Python know how to find it. This is done in one of > > three ways: > > 1) Put it in the same folder from which you run python > > 2) Put it in /lib/site-packages > > 3) Put in in some other folder and add that folder to > > your PYTHONPATH environment variable setting > > > > The easiest way for you is probably number 2. > > > > Try following this procedure: > > > > 1) Start Python to get a >>> prompt > > Which means, > 1a) Open Terminal > 1b) type python and press return > > > 2) import sys > > 3) print sys.path > > 4) use the mouse to select one of the lines that contains > > "site-packages" > > It won't be a line, it will be a long list. Depending on how your Python > is installed site-packages will be at a location like > /System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages > or > /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages > > 5) Open a Finder window > > 6) Navigate in Finder to the folder highlighted in your Python window > > 7) If necessary navigate back up to site-packages itself > > 8) Create a new sub folder and name it EasyGui > > 9) Copy easygui.py into the new folder > > 10) Create a new text file called EasyGui.pth > > 11) enter the single line "EasyGui" (without the quotes) and save/exit > > the editor > > This will work but instead of 8-11 I would just copy easygui.py into > site-packages. > > Kent > > > 12) exit python and enter it again. > > 13) type import easygui at the Python prompt. > > > > If no error messages appear you should have installed easygui > > where python can see it. > > > > NB I typed that at my PC so its from memory and untested but > > hopefully its close enough that you can figure out any discrepancies. > > > > HTH, > > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor