Re: [Tutor] Python backwards program (fwd)
[Jim, when you reply, please send to [EMAIL PROTECTED] Don't just send your reply only to me. Use your email client's Reply-To-All feature.] [Jim] > > The following gives me the last letter of the string. > > > > backwords=raw_input("enter number or string:") > > print backwords[-1] [Danny] > Yes, this is an interesting approach! We can go along this approach a > little more, if you'd like. The code above is getting the last letter, so > we're closer to printing out the word backwards. > > How would you print out the second to last letter of the string? [Jim] > To print out the second to the last letter it would be > backwords[-2] Yes. So let's see what we have so far: ## backwords=raw_input("enter number or string:") print backwords[-1] print backwords[-2] ## This works if the 'backwords' word is two letters long. So it's a partial solution: we still need to do a little bit to make this work on any word. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python backwards program (fwd)
Hello, I wanted to thank all of you who helped me with the backwards program. I finally got off my stubborn butt and downloaded 2.4.1 and the program finally works. That 2.2 was not compatible with the way I was thinking, or maybe I wasn't compatible with it was thinking who knows. i = raw_input("Enter a word.") print i[::-1] raw_input("\n\nPress the enter key to exit.") Thanks for allowing me to take some of your precious time. Jim - Original Message - From: Danny Yoo To: [EMAIL PROTECTED] Cc: Tutor Sent: Thursday, April 14, 2005 1:52 PM Subject: Re: [Tutor] Python backwards program (fwd) > Does the 2.2 python have the ability to do this?Hi Jim,Python 2.2 is actually a bit old; you may want to update the version ofPython on your system to Python 2.4. You can find it here: http://www.python.org/2.4/A lot of the approaches you were trying earlier used features that wereadded in the 2.3 or 2.4 Python series; they're absent from Python 2.2.> The following gives me the last letter of the string.>> backwords=raw_input("enter number or string:")> print backwords[-1]Yes, this is an interesting approach! We can go along this approach alittle more, if you'd like. The code above is getting the last letter, sowe're closer to printing out the word backwards.How would you print out the second to last letter of the string? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python backwards program (fwd)
> Does the 2.2 python have the ability to do this? Hi Jim, Python 2.2 is actually a bit old; you may want to update the version of Python on your system to Python 2.4. You can find it here: http://www.python.org/2.4/ A lot of the approaches you were trying earlier used features that were added in the 2.3 or 2.4 Python series; they're absent from Python 2.2. > The following gives me the last letter of the string. > > backwords=raw_input("enter number or string:") > print backwords[-1] Yes, this is an interesting approach! We can go along this approach a little more, if you'd like. The code above is getting the last letter, so we're closer to printing out the word backwards. How would you print out the second to last letter of the string? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python backwards program (fwd)
-- Forwarded message -- Date: Thu, 14 Apr 2005 00:41:40 -0500 From: Jim and Laura Ahl <[EMAIL PROTECTED]> To: Danny Yoo <[EMAIL PROTECTED]> Subject: Re: [Tutor] Python backwards program I thought you were on me a bit but I am so frustrated at this point. My instructor wrote and told me it was easy. So if it is easy why am I having so much trouble. I figured the other three programs by just reading the book and working on the computer. Does the 2.2 python have the ability to do this? I think that the program will work with something like this in an expanded form. The following gives me the last letter of the string. backwords=raw_input("enter number or string:") print backwords[-1] I have looked on a couple of sites and it says to use s.reverse() this does not work for some reason Jim Hi Jim, do you know about the dir function? You can use it to show you all methods of an object. (Methods are, more or less, the things an object comes with support for doing to it. Ugly vagueness, but roughly right.) The output of dir statements on my computer will be a bit different than yours, as I am using Python 2.4.1. But here is the result of doing dir on a string and a list: >>> dir('a string') ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'replace', 'rfind', 'rindex', 'rjust', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'] >>> dir(['a', 'list']) ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__str__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] >>> >>> 'some string'.reverse() Traceback (most recent call last): File "", line 1, in ? AttributeError: 'str' object has no attribute 'reverse' >>> And, that is what we would expect, as dir('a string') didn't show us any reverse method. *But* dir(['a', 'list']) did! So: >>> my_list = ['this', 'is', 'my', 'list'] >>> my_list.reverse() >>> my_list ['list', 'my', 'is', 'this'] >>> Does your version of Python have list.reverse()? (I've no idea when that got in, but I assume its been there since God was a lad.) If so, one way you could solve your problem would be to take a string, convert it into a list, reverse the list, and then make a string out of the list again. To try that, you will want to combine some or all of the list and str builtin functions, and the string.split and string.join methods.[*] I'm still leaving work for you to do -- which pieces and how to combine them? Give it a try and show us what you've done. [*] Really old Pythons do not have string methods at all. If yours is that old, we will have to suggest something else. Run this: >>> if 'join' in dir(str): print "My Python version has string methods" else: print "Oh, oh. I *really* need to upgrade my Python" HTH, Brian vdB ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python backwards program (fwd)
-- Forwarded message -- Date: Thu, 14 Apr 2005 00:41:40 -0500 From: Jim and Laura Ahl <[EMAIL PROTECTED]> To: Danny Yoo <[EMAIL PROTECTED]> Subject: Re: [Tutor] Python backwards program I thought you were on me a bit but I am so frustrated at this point. My instructor wrote and told me it was easy. So if it is easy why am I having so much trouble. I figured the other three programs by just reading the book and working on the computer. Does the 2.2 python have the ability to do this? I think that the program will work with something like this in an expanded form. The following gives me the last letter of the string. backwords=raw_input("enter number or string:") print backwords[-1] I have looked on a couple of sites and it says to use s.reverse() this does not work for some reason Jim - Original Message - From: Danny Yoo To: Jim and Laura Ahl Cc: Tutor ; Feziwe Mpondo Sent: Thursday, April 14, 2005 12:24 AM Subject: Re: [Tutor] Python backwards program > We're not going to do your homework problems; please understand that we > actually don't care if you get your homework done. And I really hope that > people don't just start blurting stuff at Jim for the other three homework > problems he's dumping on us. Hi Jim, Ok, I screwed up big time today, and I'd better say this in public, so that people know that I made a huge mistake. I usually make small ones that can be easily corrected, but I get the feeling I did damage today, and I wish I could take it back. Jim, I sincerely apologize about snapping at you like that. I was wrong to do so, especially since I completely misread your sentence. I thought you were saying that those were three other problems that you had to do soon, when you had actually wrote that those were three programs that you had written already. But even so, I had no excuse to say things like that. I will try to better answer your questions, without making such stupid mistakes. And I hope that folks on the list will forgive me for the bad temper in my last emails. Sincerely, Danny Yoo ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python backwards program
> We're not going to do your homework problems; please understand that we > actually don't care if you get your homework done. And I really hope that > people don't just start blurting stuff at Jim for the other three homework > problems he's dumping on us. Hi Jim, Ok, I screwed up big time today, and I'd better say this in public, so that people know that I made a huge mistake. I usually make small ones that can be easily corrected, but I get the feeling I did damage today, and I wish I could take it back. Jim, I sincerely apologize about snapping at you like that. I was wrong to do so, especially since I completely misread your sentence. I thought you were saying that those were three other problems that you had to do soon, when you had actually wrote that those were three programs that you had written already. But even so, I had no excuse to say things like that. I will try to better answer your questions, without making such stupid mistakes. And I hope that folks on the list will forgive me for the bad temper in my last emails. Sincerely, Danny Yoo ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
RE: [Tutor] Python backwards program
> In the print word [::-1] line it gives me this message > (sequence index must be an integer) What does that mean As others have said, it means you're using Python 2.2 or older (so can't use extended slicing). It seems likely that what you're after is the loop approach that has been mentioned by various people, including me. Have a go with that method, and give us the code that you have, along with any error/output that you get. =Tony.Meyer ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python backwards program
> I have wrote 3 other programs in the class. Hi Jim, [cut] Ok, that's where I have to stop you for a moment. We're not going to do your homework problems; please understand that we actually don't care if you get your homework done. And I really hope that people don't just start blurting stuff at Jim for the other three homework problems he's dumping on us. You mentioned earlier that you didn't understand backwards slices, so how can you use them with a clear conscience without knowing why they work? Why don't you ask more questions? We really care about helping you figure out how to solve your problems yourself. But if you just pick and choose answers from generous folks, and present that as your own work to your class, without really understanding what's going on, then you are wasting our time. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python backwards program (fwd)
> I cannot write a program that gives me a double letter. > I can get each letter separate or pieces or parts of the word Hi Jim, [Please don't reply just to me: use the Reply-to-All feature on your email program. This allows your reply to be seen by the rest of us here. I want to make sure your questions won't get lost by my negligence.] Can you show us what you've tried so far? That might help us see why you're running into problems. The major problem we have in trying to help with this stuff is that we can not be mind readers: the only channel we can use to see what's going on is what you show us, and if you don't give us information, we really can't see what's happening. So, when you say something like: > I cannot write a program that gives me a double letter. then, it's very useful if you can show us what you tried to do, even if it didn't work. We really don't care if you get it exactly right: we really more interested in how you do things: we really want to see how you're approaching these kinds of problems. Let's take a hypothetical situation. If you had shown us something like this: ## >>> s = "hello world" >>> for letter in s: ... print letterletter ... Traceback (most recent call last): File "", line 2, in ? NameError: name 'letterletter' is not defined ## that in itself tells us a lot more than "I can't do it." It's not just an "error": there's a reason behind it, and that's something we can tackle. The silly thing that today's education systems have done is to make the act of making a mistake or error something shameful, so I can see why you're hesitating to show things to us. But that's totally wrong: you need to be willing to show us things that don't work. A failure itself is valuable, and we can learn things from them. Continuing on this idea, when you say: > I can get each letter separate or pieces or parts of the word then, show us how you are doing that. Show us how you are printing each letter separately. Seeing what you can do can be as informative to us as seeing what you're getting stuck on. Don't be afraid to copy-and-paste programs into your replies. I guess I'm trying to say: stop being so shy about sharing your code! *grin* ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python backwards program (fwd)
-- Forwarded message -- Date: Wed, 13 Apr 2005 09:01:16 -0500 From: Jim and Laura Ahl <[EMAIL PROTECTED]> To: Danny Yoo <[EMAIL PROTECTED]> Subject: Re: [Tutor] Python backwards program (fwd) Danny I cannot write a program that gives me a double letter. I can get each letter separate or pieces or parts of the word Jim - Original Message - From: Danny Yoo To: [EMAIL PROTECTED] Cc: Tutor Sent: Wednesday, April 13, 2005 12:02 AM Subject: Re: [Tutor] Python backwards program (fwd) Hello Jim, > I have read about loops, strings, tuples. Can you show us an example of a loop? Can you show us the last program that you've written? It sounds like you've done a lot of reading. The problem with learning how to program is that you can't just read it: you actually have to write programs and watch them run. I think you need to make that book knowledge into something concrete. For example, If we give you some string, like: ## s = "hello world" ## can you get Python to say: ## hheeoo wwoorrlldd ## That is, can you write a program that will print out each letter in 's', but doubled up? > I am wasting you guys time. I do not know that. We will not do your homework for you, so if you're just expecting a direct homework solution, we will not help you, and you will be wasting our time. But if you're really interested in learning, start asking questions, and start playing with the interpreter. If there is something you do not understand yet, we'll do what we can to help you find good answers, and we'll try to point you toward resources that can help. And we'll try to be your cheering squad, if you need one. Best of wishes to you. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python backwards program
Jim and Laura Ahl wrote: Thanks for the encouragement, here is what I have so far. word=raw_input("Enter a Word or string:") print word print word[::-1] raw_input("\n\nPress the enter key to exit.") In the print word [::-1] line it gives me this message (sequence index must be an integer) What does that mean What version of Python are you using? "Extended slices" like print word[::-1] have only been supported since Python 2.3. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python backwards program
Thanks for the encouragement, here is what I have so far. word=raw_input("Enter a Word or string:") print word print word[::-1] raw_input("\n\nPress the enter key to exit.") In the print word [::-1] line it gives me this message (sequence index must be an integer) What does that mean I have wrote 3 other programs in the class. A famous quote program where the user inputs their favorite quote, and author and it prints it out. Two number program the user inputs two numbers and the program adds them together, subtracts, multiply, divide, and hexed. A fortune cookie program that randomly gives one fortune out of 5 to the user. Jim - Original Message - From: Feziwe Mpondo To: Alberto Troiano Cc: [EMAIL PROTECTED] ; tutor@python.org Sent: Wednesday, April 13, 2005 10:14 AM Subject: Re: [Tutor] Python backwards program Alberto Troiano wrote:> You can do this:>> >>> word=raw_input("Type the word: ")> Type the word: Kokiri Forest> >>> print word> Kokiri Forest> >>> print word[::-1]> tseroF irikoK>> But I saw that this gave you a hard time so this is an alternate > longer way:>> >>> backword=""> >>> counter=len(word)>> >>> while counter!=0:> backword+=word[counter-1]> counter-=1>> >>> print backword> tseroF irikoK>> So choose the one you want and feel free to ask in case of any doubt>> Regards>> Alberto>>> Gaucho> >From: "Jim and Laura Ahl" <[EMAIL PROTECTED]> >To: <tutor@python.org> > >Subject: [Tutor] Python backwards program >Date: Tue, 12 Apr 2005 > 20:05:41 -0500 > >I am very new to programming and I have an > assignment to have a raw_input string that is inputted by the user and > then is printed backwards. Can anyone help me? I can get it to print > regular but backwards in not working. > >Thank You >Jim > >___ >Tutor maillist - > Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor>>>>___>Tutor maillist - Tutor@python.org>http://mail.python.org/mailman/listinfo/tutor> >i am able to type, what i can't seem to do is seeing it print or executing the command on the shell window ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python backwards program
OK. I'm assuming that you're writing a .py document and you want it to run by double-clicking it in the shell, right??? And you can't see the output of your prog(that's my problem to understand English, sorry :/) If this is your problem then add at the very bottom of your file this sentence: raw_input() Your program will wait until you press any key to finish. If you want to make it fancy then put a string to show inside the parenthesis Let me know if this solve your problem and if that's not the problem then sorry for misunderstanding you and I beg you post again a little more specific (that's only applied to me :)) Regards Alberto Gaucho>From: Feziwe Mpondo <[EMAIL PROTECTED]> >To: Alberto Troiano <[EMAIL PROTECTED]> >CC: [EMAIL PROTECTED], tutor@python.org >Subject: Re: [Tutor] Python backwards program >Date: Wed, 13 Apr 2005 17:14:46 +0200 > >Alberto Troiano wrote: > >>You can do this: >> >> >>> word=raw_input("Type the word: ") >>Type the word: Kokiri Forest >> >>> print word >>Kokiri Forest >> >>> print word[::-1] >>tseroF irikoK >> >>But I saw that this gave you a hard time so this is an alternate >>longer way: >> >> >>> backword="" >> >>> counter=len(word) >> >> >>> while counter!=0: >> backword+=word[counter-1] >> counter-=1 >> >> >>> print backword >>tseroF irikoK >> >>So choose the one you want and feel free to ask in case of any >>doubt >> >>Regards >> >>Alberto >> >> >> Gaucho >> >From: "Jim and Laura Ahl" <[EMAIL PROTECTED]> >To: >> >Subject: [Tutor] Python backwards program >> >Date: Tue, 12 Apr 2005 20:05:41 -0500 > >I am very new to >>programming and I have an assignment to have a raw_input string >>that is inputted by the user and then is printed backwards. Can >>anyone help me? I can get it to print regular but backwards in not >>working. > >Thank You >Jim >> >___ >Tutor maillist - >>Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor >> >> >> >>___ >>Tutor maillist - Tutor@python.org >>http://mail.python.org/mailman/listinfo/tutor >> >> >i am able to type, what i can't seem to do is seeing it print or >executing the command on the shell window ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python backwards program
Alberto Troiano wrote: You can do this: >>> word=raw_input("Type the word: ") Type the word: Kokiri Forest >>> print word Kokiri Forest >>> print word[::-1] tseroF irikoK But I saw that this gave you a hard time so this is an alternate longer way: >>> backword="" >>> counter=len(word) >>> while counter!=0: backword+=word[counter-1] counter-=1 >>> print backword tseroF irikoK So choose the one you want and feel free to ask in case of any doubt Regards Alberto Gaucho >From: "Jim and Laura Ahl" <[EMAIL PROTECTED]> >To: >Subject: [Tutor] Python backwards program >Date: Tue, 12 Apr 2005 20:05:41 -0500 > >I am very new to programming and I have an assignment to have a raw_input string that is inputted by the user and then is printed backwards. Can anyone help me? I can get it to print regular but backwards in not working. > >Thank You >Jim >___ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor i am able to type, what i can't seem to do is seeing it print or executing the command on the shell window ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
RE: [Tutor] Python backwards program
You can do this: >>> word=raw_input("Type the word: ")Type the word: Kokiri Forest>>> print wordKokiri Forest>>> print word[::-1]tseroF irikoKBut I saw that this gave you a hard time so this is an alternate longer way: >>> backword="">>> counter=len(word) >>> while counter!=0: backword+=word[counter-1] counter-=1 >>> print backwordtseroF irikoK So choose the one you want and feel free to ask in case of any doubt Regards Alberto Gaucho>From: "Jim and Laura Ahl" <[EMAIL PROTECTED]> >To: >Subject: [Tutor] Python backwards program >Date: Tue, 12 Apr 2005 20:05:41 -0500 > >I am very new to programming and I have an assignment to have a raw_input string that is inputted by the user and then is printed backwards. Can anyone help me? I can get it to print regular but backwards in not working. > >Thank You >Jim >___ >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] Python backwards program (fwd)
> We will not do your homework for you [snip] The slicing answer I posted is possibly the answer, but I assume that the loop solution, which I didn't post (in Python), is what is actually required. If slicing is what is wanted, then I apologise for giving an answer! :) =Tony.Meyer ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
RE: [Tutor] Python backwards program (fwd)
> I have read about loops, strings, tuples. I am taking this > class on distance education and I am lost with this > assignment. I have read what Tony has wrote and that does me > no good. I do not understand what he is talking about. Which bits? The whole lot? I teach university students programming, so maybe the language doesn't fit with you. Whatever it is, just say what doesn't make sense and I'll happily rephrase it, or expand, or whatever is needed. > I understand how slicing works and what the numbers mean. I > know what the -1 and such like that mean. I know what the > len function does. Why then do you not understand that the answer is simply this? """ my_string = raw_input("Prompt:") print my_string[::-1] """ (I'm not trying to be offensive; I would like to know why you don't understand that, if you understand how slicing works). As Danny said, if you can't simply use slicing (it is pretty simple), then you're probably after a loop. You want to run through the string, but with a negative step. The most explicit way to do this is to have an index variable that keeps track of where you are up to in the string. Normally this would go from 0 to the length of the string, but you want it to go backwards, so from the length of the string to 0. Each time around the loop, you want the index to go down one. So: start index at length of string while index has not reached 0: print character at string[index] decrease index by one Do you see what that is doing? It translates very simply into Python (one of the advantages of the language): index = len(my_string) while index >= 0: print my_string[index] index = index -1 This will of course print out the string one character per line, which isn't what you want. But that's easy enough to change. There are other ways of doing this, but I suspect something like the above is what you are after in a beginning course. You could, for example, build a new (reversed) string, rather than printing it out as you go, and then print that out. In C, it would look something like this: """ for (unsigned int i==0; ++i) { printf("%c", my_string[i]); } """ Which is a fairly common sort of exercise when you're learning C, since C doesn't have the nice slicing capabilities that Python does. > I am wasting you guys time. Not at all. We come here to try and help. =Tony.Meyer ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python backwards program (fwd)
for the slicing see: http://docs.python.org/lib/typesseq.html for a longhand loop approach see: http://docs.python.org/tut/node6.html#SECTION00620 On Apr 13, 2005, at 12:46 AM, Danny Yoo wrote: -- Forwarded message -- Date: Tue, 12 Apr 2005 22:37:44 -0500 From: Jim and Laura Ahl <[EMAIL PROTECTED]> To: Danny Yoo <[EMAIL PROTECTED]> Subject: Re: [Tutor] Python backwards program I have read about loops, strings, tuples. I am taking this class on distance education and I am lost with this assignment. I have read what Tony has wrote and that does me no good. I do not understand what he is talking about. I understand how slicing works and what the numbers mean. I know what the -1 and such like that mean. I know what the len function does. I am wasting you guys time. Thanks Jim - Original Message - From: Danny Yoo To: Tony Meyer Cc: 'Jim and Laura Ahl' ; tutor@python.org Sent: Tuesday, April 12, 2005 9:09 PM Subject: RE: [Tutor] Python backwards program On Wed, 13 Apr 2005, Tony Meyer wrote: I am very new to programming and I have an assignment to have a raw_input string that is inputted by the user and then is printed backwards. Can anyone help me? I can get it to print regular but backwards in not working. I guess that I shouldn't give code if this is for an assignment, but if you are using Python 2.4, then try seeing what the "reversed()" built-in function does. If you're not using Python 2.4, then read up about "slices" - which is when you get subsections of a string (e.g. "tony"[2:4] is "ny"). You can pass a 'direction' in a slice as well. It might also help to have a better feeling for what Jim already knows. If this is a school assignment, I doubt that reversed() is allowed, nor reverse slices, since that would make the problem too easy. *cough* Jim, can you give a brief description of what things you've learned already? Do you already know about loops? ___ 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] Python backwards program (fwd)
Hello Jim, > I have read about loops, strings, tuples. Can you show us an example of a loop? Can you show us the last program that you've written? It sounds like you've done a lot of reading. The problem with learning how to program is that you can't just read it: you actually have to write programs and watch them run. I think you need to make that book knowledge into something concrete. For example, If we give you some string, like: ## s = "hello world" ## can you get Python to say: ## hheeoo wwoorrlldd ## That is, can you write a program that will print out each letter in 's', but doubled up? > I am wasting you guys time. I do not know that. We will not do your homework for you, so if you're just expecting a direct homework solution, we will not help you, and you will be wasting our time. But if you're really interested in learning, start asking questions, and start playing with the interpreter. If there is something you do not understand yet, we'll do what we can to help you find good answers, and we'll try to point you toward resources that can help. And we'll try to be your cheering squad, if you need one. Best of wishes to you. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python backwards program (fwd)
-- Forwarded message -- Date: Tue, 12 Apr 2005 22:37:44 -0500 From: Jim and Laura Ahl <[EMAIL PROTECTED]> To: Danny Yoo <[EMAIL PROTECTED]> Subject: Re: [Tutor] Python backwards program I have read about loops, strings, tuples. I am taking this class on distance education and I am lost with this assignment. I have read what Tony has wrote and that does me no good. I do not understand what he is talking about. I understand how slicing works and what the numbers mean. I know what the -1 and such like that mean. I know what the len function does. I am wasting you guys time. Thanks Jim - Original Message - From: Danny Yoo To: Tony Meyer Cc: 'Jim and Laura Ahl' ; tutor@python.org Sent: Tuesday, April 12, 2005 9:09 PM Subject: RE: [Tutor] Python backwards program On Wed, 13 Apr 2005, Tony Meyer wrote: > > I am very new to programming and I have an assignment to have a > > raw_input string that is inputted by the user and then is printed > > backwards. Can anyone help me? I can get it to print regular but > > backwards in not working. > > I guess that I shouldn't give code if this is for an assignment, but if > you are using Python 2.4, then try seeing what the "reversed()" built-in > function does. If you're not using Python 2.4, then read up about > "slices" - which is when you get subsections of a string (e.g. > "tony"[2:4] is "ny"). You can pass a 'direction' in a slice as well. It might also help to have a better feeling for what Jim already knows. If this is a school assignment, I doubt that reversed() is allowed, nor reverse slices, since that would make the problem too easy. *cough* Jim, can you give a brief description of what things you've learned already? Do you already know about loops? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
RE: [Tutor] Python backwards program
On Wed, 13 Apr 2005, Tony Meyer wrote: > > I am very new to programming and I have an assignment to have a > > raw_input string that is inputted by the user and then is printed > > backwards. Can anyone help me? I can get it to print regular but > > backwards in not working. > > I guess that I shouldn't give code if this is for an assignment, but if > you are using Python 2.4, then try seeing what the "reversed()" built-in > function does. If you're not using Python 2.4, then read up about > "slices" - which is when you get subsections of a string (e.g. > "tony"[2:4] is "ny"). You can pass a 'direction' in a slice as well. It might also help to have a better feeling for what Jim already knows. If this is a school assignment, I doubt that reversed() is allowed, nor reverse slices, since that would make the problem too easy. *cough* Jim, can you give a brief description of what things you've learned already? Do you already know about loops? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
RE: [Tutor] Python backwards program
> I am very new to programming and I have an assignment > to have a raw_input string that is inputted by the user > and then is printed backwards. Can anyone help me? I can > get it to print regular but backwards in not working. I guess that I shouldn't give code if this is for an assignment, but if you are using Python 2.4, then try seeing what the "reversed()" built-in function does. If you're not using Python 2.4, then read up about "slices" - which is when you get subsections of a string (e.g. "tony"[2:4] is "ny"). You can pass a 'direction' in a slice as well. =Tony.Meyer ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor