[Tutor] Tutor Ilde running problems
Hi all, Just installed python 2.7.2 on my windows 7 32-bit laptop. However when I attempt to run idle it wont open (nothing happens) Wondered if any of you have had this problem and have any tips? Cheers> ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
Hi all, I'm new to programming (thus Python), so after reading the basics, I wanted to practise what I've learnt . I've come across a beginners exercise which is to programme rot13. I've written some code but it doesn't seem to work Here it is: def rot13(s):char_low = ()result = ""if not s.isalpha(): return charchar_low = char_low.lower()if char_low <= 'm': dist = 13else:dist = -13char = chr(ord(char) + dist) def rot13_char(ch): return ''.join( rot13(s) for char in ch ) Any idea where i'm wrong? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Rot13
Hi all, I'm new to programming (thus Python), so after reading the basics, I wanted to practise what I've learnt . I've come across a beginners exercise which is to write the code for rot13. I've written some code but it doesn't seem to work When I run it I get this error: NameError: global name 'rot13_char' is not defined Here it is: def rot13(s): char_low = () result = "" if not s.isalpha(): return char char_low = char_low.lower() if char_low <= 'm': dist = 13 else: dist = -13 char = chr(ord(char) + dist) def rot13(string): return ''.join( rot13_char(char)for char in string ) Any ideas where i'm wrong? Huge thanks, Nidian ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Rot13
Sorry about the code format in last E-mail. I'll attach the code in notepad, as my e-mail doesnt seem to like sending plain text.. > From: nidia...@hotmail.com > To: st...@pearwood.info; tutor@python.org > Date: Thu, 17 Nov 2011 17:45:11 + > Subject: [Tutor] Rot13 > > > Hi all, > > I'm new to programming (thus Python), so after reading the basics, I wanted > to practise what I've learnt . > I've come across a beginners exercise which is to write the code for rot13. > I've written some code but it doesn't seem to work > When I run it I get this error: > > > NameError: global name 'rot13_char' is not defined > > > Here it is: > > > > def rot13(s):char_low = ()result = ""if not s.isalpha(): > return charchar_low = char_low.lower()if char_low <= 'm': >dist = 13else:dist = -13char = chr(ord(char) + > dist) def rot13(string): return ''.join( rot13_char(char)for > char in string ) > > > > > Any ideas where i'm wrong? > > Huge thanks, > Nidian > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor def rot13(s): """ >>> type(rot13("bob")) >>> len(rot13("foobar")) 6 >>> rot13("abc") 'nop' >>> rot13("XYZ") 'KLM' >>> rot13('5 The Parade') '5 Gur Cnenqr' >>> rot13('5 Gur Cnenqr') '5 The Parade' """ char_low = () result = "" if not s.isalpha(): return char char_low = char_low.lower() if char_low <= 'm': dist = 13 else: dist = -13 char = chr(ord(char) + dist) def rot13(string): return ''.join( rot13_low(char)for char in string ) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Encoding
Hi all, In my programme I am encoding what the user has in-putted. What the user inputs will in a string, which might a mixture of letters and numbers. However I only want the letters to be encoded. Does any-one how I can only allow the characters to be encoded ?? Big thanks, ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Doctest error!
> Date: Thu, 17 Nov 2011 22:49:33 -0500 > From: d...@davea.name > To: nidia...@hotmail.com > CC: tutor@python.org > Subject: Re: [Tutor] Doctest error! > > On 11/18/2011 10:29 AM, John wrote: > > > > Hi all, > > When i run a doctest on this piece of code (shown at bottom) i get > > this error message [from the doctest]: > > > > > > > > Trying: > > rot13('5 The Parade') > > Expecting: > > '5 Gur Cnenqr' > > ** > > File "F:\Uni\Rot13_1.py", line 12, in Rot13_1.rot13 > > Failed example: > > rot13('5 The Parade') > > Expected: > > '5 Gur Cnenqr' > > Got: > > 'B-aur-]n\x7fnqr' > > Trying: > > rot13('5 Gur Cnenqr') > > Expecting: > > '5 The Parade' > > ** > > File "F:\Uni\Rot13_1.py", line 14, in Rot13_1.rot13 > > Failed example: > > rot13('5 Gur Cnenqr') > > Expected: > > '5 The Parade' > > Got: > > 'B-T\x82\x7f-P{r{~\x7f' > > > > > > > > An one have any idea why? (I'm guessing its to do with the numbers) > > > > > > code: > > > > def rot13(s): > > > > """ > > >>> type(rot13("bob")) > > > > >>> len(rot13("foobar")) > > 6 > > >>> rot13("abc") > > 'nop' > > >>> rot13("XYZ") > > 'KLM' > > >>> rot13('5 The Parade') > > '5 Gur Cnenqr' > > >>> rot13('5 Gur Cnenqr') > > '5 The Parade' > > """ > > result = '' # initialize output to empty > > for char in s: # iterate over string > > if int: > > char_low = s.lower() > > if char_low<= 'm': > > dist = 13 > > else: > > dist = -13 > > char = chr(ord(char) + dist) > > result+=char > > return result > > The line "if int:" is clearly wrong. Did you write this code > yourself, or was it typed in from a listing somewhere? I'd assume that > you wanted to do some check on the char value. But if int will always > be true. > > > > > -- > > DaveA I want it to look in s, and only perform this code on the letters in s(not numbers): char_low = s.lower() if char_low <= 'm': dist = 13 else: dist = -13 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] IndexError: list index out of range
To answer your questions Steven What is the intention of this function? The name given doesn't mean anything to me. The parameters "names" and "step" don't seem meaningful. I can see what the function does: it deletes bits of something, probably a list, in a convoluted way, eventually causing an error. But I can't tell what it is *supposed* to do. Given the example you show later on: survivor(["Andrew", "Brenda", "Craig", "Deidre", "Edward", "Felicity", "Greg", "Harriet"], 4) what should the result be? To answer your questions Steven What is the intention of this function? The name given doesn't mean anything to me. The parameters "names" and "step" don't seem meaningful. The intention of the programme is to remove every Nth person from a list. N (defined as steps) is inputted by the user. I can see what the function does: it deletes bits of something, probably a list, in a convoluted way, eventually causing an error. But I can't tell what it is *supposed* to do. Given the example you show later on: survivor(["Andrew", "Brenda", "Craig", "Deidre", "Edward", "Felicity", "Greg", "Harriet"], 4) what should the result be? In the example Survivor (["Andrew", "Brenda", "Craig", "Deidre", "Edward", "Felicity", "Greg", "Harriet"], 3) He answer should be ‘Greg’ > Date: Tue, 22 Nov 2011 10:02:01 +1100 > From: st...@pearwood.info > To: tutor@python.org > Subject: Re: [Tutor] IndexError: list index out of range > > John wrote: > > > > Hi all, > > > > I have wriiten the following code: > > [Segment] > > > def survivor(names, step): > > index = step - 1 > > next = names > > while len(next)> 1: > > next.remove (next[index]) > > > What is the intention of this function? The name given doesn't mean > anything to me. The parameters "names" and "step" don't seem meaningful. > > I can see what the function does: it deletes bits of something, probably > a list, in a convoluted way, eventually causing an error. But I can't > tell what it is *supposed* to do. > > > Given the example you show later on: > > survivor(["Andrew", "Brenda", "Craig", "Deidre", "Edward", > "Felicity", "Greg", "Harriet"], 4) > > > what should the result be? > > > > However when ever i run it i get this error message: > > > > Traceback (most recent call last): > > File "", line 1, in > > survivor(["Andrew", "Brenda", "Craig", "Deidre", "Edward", > > "Felicity", "Greg", "Harriet"], 4) > > File "", line 5, in survivor > > next.remove (next[index]) > > IndexError: list index out of range > > > > Any ideas about whats causing this error? > > > You attempt to delete an item that doesn't exist. > > > > > -- > Steven > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor