Re: [Tutor] Newb Learning Question
bob gailer [EMAIL PROTECTED] wrote 3rd alternative: if c 'm': print c Wow! Amazingly I just assumed you couldn't directly compare characters with boolean tests. I don't know why I thought that since it must be possible for string comparisons, but I did. You learn something new every day, :-) Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Newb Learning Question
3rd alternative: if c 'm': print c after futzing around with interpreting the problem, I ended up with a solution that utilizes the character comparison. Write a program that prints the first letter of a string that comes after 'm' in the alphabet. s = this is my string for i in s: if i 'm': print i break Thanks for all the help everyone. Seems so obvious now.. ;-) I'm sure I'll be back with some more newb questions in the future. ;-) jeff. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Newb Learning Question
Should be replying to the listSorry :( On Thu, Apr 3, 2008 at 11:14 AM, Sander Sweers [EMAIL PROTECTED] wrote: On Thu, Apr 3, 2008 at 8:21 AM, Jeffrey Dates [EMAIL PROTECTED] wrote: 3rd alternative: if c 'm': print c snip Write a program that prints the first letter of a string that comes after 'm' in the alphabet. s = this is my string for i in s: if i 'm': print i break One potential problem you will have is with upper case letters. 'N' 'm' False To make input all lower case use .lower() 'N'.lower() 'm' True Greets Sander ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Newb Learning Question
Exellent suggestion! thanks! On Thu, Apr 3, 2008 at 2:17 PM, Sander Sweers [EMAIL PROTECTED] wrote: Should be replying to the listSorry :( On Thu, Apr 3, 2008 at 11:14 AM, Sander Sweers [EMAIL PROTECTED] wrote: On Thu, Apr 3, 2008 at 8:21 AM, Jeffrey Dates [EMAIL PROTECTED] wrote: 3rd alternative: if c 'm': print c snip Write a program that prints the first letter of a string that comes after 'm' in the alphabet. s = this is my string for i in s: if i 'm': print i break One potential problem you will have is with upper case letters. 'N' 'm' False To make input all lower case use .lower() 'N'.lower() 'm' True Greets Sander ___ 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] Newb Learning Question
Greetings, I have no previous experience in scripting. Python is my first language... I'm currently trying to build a logic model for how to 'think' in Python, so please excuse my ignorance. Currently, I'm running through some basic 101 tutorials, to wrap my head around solving problems. I'm looking for some advice on how to solve the following exercise: Write a program that prints the first letter of a string that comes after 'm' in the alphabet. I hope this is not too elementary. I do understand basic, basic concepts. iteration, for loops, etc. Just having trouble with syntax, and how to format my logic. thank you in advance for any help or examples. Jeffrey Dates www.kungfukoi.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Newb Learning Question
Sorry forgot to post what I had so far: for code in range(ord(a), ord(z) +1): if code == ord(m): print chr(code +1) Now, this solves for the first letter after M, but doesn't do it via a string thanks, Jeffrey Dates www.kungfukoi.com On Wed, Apr 2, 2008 at 12:44 PM, Jeffrey Dates [EMAIL PROTECTED] wrote: Greetings, I have no previous experience in scripting. Python is my first language... I'm currently trying to build a logic model for how to 'think' in Python, so please excuse my ignorance. Currently, I'm running through some basic 101 tutorials, to wrap my head around solving problems. I'm looking for some advice on how to solve the following exercise: Write a program that prints the first letter of a string that comes after 'm' in the alphabet. I hope this is not too elementary. I do understand basic, basic concepts. iteration, for loops, etc. Just having trouble with syntax, and how to format my logic. thank you in advance for any help or examples. Jeffrey Dates www.kungfukoi.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Newb Learning Question
On Wed, Apr 2, 2008 at 12:50 PM, Jeffrey Dates [EMAIL PROTECTED] wrote: Sorry forgot to post what I had so far: for code in range(ord(a), ord(z) +1): if code == ord(m): print chr(code +1) Now, this solves for the first letter after M, but doesn't do it via a string thanks, Let's think about the problem in pseudocode: If the first letter in the string comes after m in the alphabet, print that letter. Otherwise, if the second letter comes after m in the alphabet, print *that* letter. etc. etc. So what you want is to *iterate* through the characters that make up the string (from start to end) until you find a character that comes after m. Your code above seems to *iterate* through all the characters from a to z, not the characters of a given string. See if you can fix that first, then we'll talk about the next step. Tony R. aka Taser Jeffrey Dates www.kungfukoi.com On Wed, Apr 2, 2008 at 12:44 PM, Jeffrey Dates [EMAIL PROTECTED] wrote: Greetings, I have no previous experience in scripting. Python is my first language... I'm currently trying to build a logic model for how to 'think' in Python, so please excuse my ignorance. Currently, I'm running through some basic 101 tutorials, to wrap my head around solving problems. I'm looking for some advice on how to solve the following exercise: Write a program that prints the first letter of a string that comes after 'm' in the alphabet. I hope this is not too elementary. I do understand basic, basic concepts. iteration, for loops, etc. Just having trouble with syntax, and how to format my logic. thank you in advance for any help or examples. Jeffrey Dates www.kungfukoi.com ___ 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] Newb Learning Question
Jeffrey Dates wrote: Greetings, I have no previous experience in scripting. Python is my first language... I'm currently trying to build a logic model for how to 'think' in Python, so please excuse my ignorance. Currently, I'm running through some basic 101 tutorials, to wrap my head around solving problems. I'm looking for some advice on how to solve the following exercise: Write a program that prints the first letter of a string that comes after 'm' in the alphabet. what I had so far: for code in range(ord(a), ord(z) +1): if code == ord(m): print chr(code +1) Now, this solves for the first letter after M which is NOT what the exercise wants! Consider are you ready?. Which character is the first that comes after 'm' in the alphabet.? BTW did you mean after m? Caps and lower case are different. , but doesn't do it via a string I for one am reluctant to just give an answer. I prefer to lead you to a solution. So, I suggest you write a program to: assign a candidate string to a variable (choose a string that has at least one letter that comes after 'm') test each character to see if it comes after 'm' print that character stop Do as much as you can, and ask more questions. -- Bob Gailer 919-636-4239 Chapel Hill, NC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Newb Learning Question
That's Bob, and Tony, exactly what I'm looking for. ( not the answer, but the path to it... ) Let me get back to you with my result after I study this a bit. thanks!! Jeffrey Dates www.kungfukoi.com On undefined, bob gailer [EMAIL PROTECTED] wrote: Jeffrey Dates wrote: Greetings, I have no previous experience in scripting. Python is my first language... I'm currently trying to build a logic model for how to 'think' in Python, so please excuse my ignorance. Currently, I'm running through some basic 101 tutorials, to wrap my head around solving problems. I'm looking for some advice on how to solve the following exercise: Write a program that prints the first letter of a string that comes after 'm' in the alphabet. what I had so far: for code in range(ord(a), ord(z) +1): if code == ord(m): print chr(code +1) Now, this solves for the first letter after M which is NOT what the exercise wants! Consider are you ready?. Which character is the first that comes after 'm' in the alphabet.? BTW did you mean after m? Caps and lower case are different. , but doesn't do it via a string I for one am reluctant to just give an answer. I prefer to lead you to a solution. So, I suggest you write a program to: assign a candidate string to a variable (choose a string that has at least one letter that comes after 'm') test each character to see if it comes after 'm' print that character stop Do as much as you can, and ask more questions. -- Bob Gailer 919-636-4239 Chapel Hill, NC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Newb Learning Question
Jeffrey Dates [EMAIL PROTECTED] wrote Let me get back to you with my result after I study this a bit. thanks!! One wee tip you might find useful. To test if a lertter comes after 'm you could a) create a string with all letters after m after_m = 'nopqrstuvwxyz' then test whether your characters were in after_m: if c in after_m: print c OR b) see if the ascii value of your character is bigger than the ascii value of 'm' And you can check the ascii value using ord() There are pros and cons to both approaches. Pick the one you like best, we can debate the ideal solution for any given case later... 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
Re: [Tutor] Newb Learning Question
Alan Gauld wrote: Jeffrey Dates [EMAIL PROTECTED] wrote Let me get back to you with my result after I study this a bit. thanks!! One wee tip you might find useful. To test if a lertter comes after 'm you could a) create a string with all letters after m after_m = 'nopqrstuvwxyz' then test whether your characters were in after_m: if c in after_m: print c OR b) see if the ascii value of your character is bigger than the ascii value of 'm' And you can check the ascii value using ord() 3rd alternative: if c 'm': print c There are pros and cons to both approaches. Pick the one you like best, we can debate the ideal solution for any given case later... -- Bob Gailer 919-636-4239 Chapel Hill, NC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor