[Courses] [python] Lesson 2: Loops, if, and beer

Ivan Avery Frey ivan.avery.frey at gmail.com
Sat Jun 25 05:11:47 UTC 2011


On 24/06/11 21:04, Leslie wrote:
> Two questions from this lesson:
>>
>> At the Python>>>  prompt, try typing:
>> range(10, 2)
>> [2, 4, 6, 8]
> I didn't get that. I got:
> >>> range(10, 2)
> []

I think range(2,10,2) was intended here.

>> for i in range(1, 6) :
>>      if i == 3 :
>>          print "i is three!"
>>      elif i == 4 :
>>          print "now it's four!"
>>      else :
>>          print "Hello, world! i =", i
> 
> This question is about interactive (console) Python.
> I entered the above but had a typo in the first line so I got an error
> message.  Is there a way to correct a line retroactively when you are in
> interactive Python (>>>) mode -- so you don't have to just enter the
> whole thing all over again?

It appears you have to enter the thing all over again, but you can use the history function (the cursor up key) to retrieve previous commands (the cursor up key). Tedious at best, I prefer to use an editor.

Ivan.


More information about the Courses mailing list