[Tutor] double result ...
alan.gauld at blueyonder.co.uk
Sun Nov 16 19:23:48 EST 2003
>>> for i in range(a,b,c):
Let's look at this more closely.
You called range(7,9,8)
that returns a list of values from 7 to (9-1) separated by 8.
That means you only get one value, 7.
try it by typing range() at the >>> prompt. Experiment with
some values till you understand how it works.
> sequence" for computer (it doesn't support alphabet) !!
Support for the alphabet is another issue and nothing to do
with what's happening here. Lets come back to that later.
>>> for d in range(a,b,c):
This time you created a list from 4 to (6-1) stepping by 8
- again the single value 4
>>> for d in range(b,c):
This time a list from 6 to 8-1, that is 6 and 7.
So you have two values that d is set to and so you print b twice.
What I think you shjould have written was:
for d in [a,b,c]:
That is, instead of using range() to create a list you just create the
list by hand.
As for letters, you can access them using the predefined sequence in
for char in string.letters:
for char in string.uppercase:
and so on. Take a look at the string module to see what other
Author of the Learn to Program web tutor
More information about the Tutor