[Tutor] Still the Python Challenge

Alan Gauld alan.gauld at btinternet.com
Tue Jan 3 20:09:03 CET 2012


On 03/01/12 17:44, Joaquim Santos wrote:

>   - How to correctly populate a list using, for instance, a for loop;
>

I can't tell what you had because the formatting got lost in the email 
ether...

>   - how to correctly use join to read the said list in a human friendly way...

You seem to be doing that OK as is. Do you think you have a problem with it?

> This was the code I was using.
>
> for letter in cypheredText:
>
> asciiValue = ord(letter)
>
> if asciiValue in range(97, 123):
>
> asciiValue += shiftedCypherNumber
>
> if asciiValue>  122:
>
> asciiValue -= 26
>
> newLetter = chr(asciiValue)
>

Up to her is OK, but...

Asssuming this next line is still inside the for loop?

> text = list()

If this is in the loop then you create a new list for every letter.
And you override the previous one so losing it...
You probably want this before the loop. Its more usual to just do

text = []

though.... But both techniques work.

> text.append(newLetter)
>
> joinedText = ' '.join(text)

This is right but your text only has a single value in it
as explained above.

> Thanks for all your time and patience. Sorry for before not using Plain text!

It seems something is still broken! :-(

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list