Re: [Tutor] Newbie Anxiety

2005-11-11 Thread Alan Gauld
Ah, memory lane time again :-)

A good natured word of explanation for Chris and others:
 10 FORN=1TO10:?N:NEXTN: REM  It is bad form not to name N after NEXT to
 label which FOR NEXT loop is being incremented.

Oh, you had advanced BASIC - it allowed nested for loops! :-)
My first BASIC only allowed for loops that could be written in a single
line...Anything more complex you had to call a subroutine with GOSUB.

 and replacing big IBM systems with tiny multi-user systems, and we had
 only 48,000 bytes of RAM CORE, of which 20,500 bytes was used for the
 entire operating system,

Yes, I remember those days, in fact 48K was quite generous!
My original box only had 16K RAM and 16K ROM for the OS and interpreter.

 SPEED, which meant a lightning fast BASIC (which we hired Steve Jobs to

Ah yes, now there's another difference. Our BASIC was SLOW!
The machine was slow too, it had a 500KHz clock - yes, half a megahertz!

 accomplished in a single program, thus forcing a jump to a new program,
 all of which again cut down on speed of getting things done because we
 had to write our variables to disk before making the jump,

You had Disks?!! We were using loops of punched tape...

 reloaded them in the chained program next to be executed making a big
 PAUSE in the process of processing.

Yes, the forerunner of Overlay programming, I used to have such fun
debugging Overlays! :-(

 line-number-orientated language, and GOTO naturally follows as the size
 of the program increases.

And here we have another advanced feature. Our BASIC didn't renumber
GOTO or GOSUB statements, you had to do that manually. Thats why we
used a lot of GOSUB but very few GOTO. And SUBs were all given 1000
lines each to minimise risk of renumbering...

 point of view, that the real grade for excellence that counts, is the
 real world reward of what happens and continues to happen with your
 business's bank account.

Depends on how you measure excellence. A lot of excellent software has
been written by companies that went bust. The software was sufficiently
excellent to survive and be bought out or just made publicly available as
open source. So excellence can also be measured on how long lived the
software is regardless of how long lived be the commercial body that created
it.

 And while I am sure someone is thinking Spaghetti Code, our style was
 highly conventionalized, something that we enforced rather strictly.

Yep you can write structured assembly and spaghetti Python. Its ultimately
about behaviours not language.

 writing 99% of our code in Basic. (IT WAS A VERY
 VERY VERY FAST BASIC.) So, you see, Basic was my ONLY language.

But I've fortunately never been limited to one language, even on my most
primitive machines I've had recourse to assembler, and usually some kind
of scripting environment. Only on very early PCs, where BASIC was the OS
was I so restricted - and PEEK/POKE were my friends :-).

 only real concern has been in how the flow of python works for the WHOLE
 PROGRAM FLOW, and you all have help me a lot here...and I really

One of the things that some folks find hard is divorcing themselves from 
that
old line by line way of thinking. Modern languages can seem a little like
black magic at times(*) - especially when you start programming with 
objects.
The trick is to trust the language and just believe it will work! :-)

(*)I'm having the same problem right now with the JSP Tomcat/Struts
framework where all sorts of magical things just seem to happen. I keep
fighting my desire to go trawl through the source code to see what's going
on. Then I tell myself  ' just trust in the force Luke...'

Enjoy your voyage of discovery and question us freely here on tutor.

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie Anxiety

2005-11-10 Thread John Fouhy
On 11/11/05, Terry Kemmerer [EMAIL PROTECTED] wrote:
  I'm working on Ch. 5, Fruitful Functions, or How To Think Like A
 Computer Scientist and I still can't count.
  (Don't laugh! I can't play the violin either...)

  In Basic, I would have said:

  10  x = x + 1 :  print x : goto 10

  run
  1
  2
  3
  etc

  How is this done in Python? (So I can stop holding my breath as I study
 this great languageand relax.)

Hi Terry,

There's a couple of options.

First, we could do it with a while loop.  This is not the best or the
most idiomatic way, but it's probably most similar to what you've seen
before.

 count forever
i = 0
while True:
print i
i = i + 1


Of course, we generally don't want to keep counting forever.  Maybe
we'll count up to 9.

 count to 9
i = 0
while i  10::
print i
i = i + 1


A while loop contains an implicit GOTO start at the end.  At the
start, it checks the condition, and breaks out of the loop if the
condition is false.

Like i said, though, this is not idiomatic Python.  Python has for
loops which are based around the idea of iterating over a sequence. 
So, we could count to 9 like this:

 count to 9
for i in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
print i


The loop will go through the list, assigning each item to i in turn,
until the list is exhausted.  The range() function is useful for
building lists like that, so we don't have to type it out manually.

 count to 9
for i in range(10):
print i


And, of course, once we've got range(), we can give it a variable
limit (eg, n = 10; range(n)).  Iteration is the key to doing all kinds
of funky stuff in python (including new ideas like geneartor
functions), so it's good to get the hang of :-)

--
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie Anxiety

2005-11-10 Thread Kent Johnson
Terry Kemmerer wrote:
 In Basic, I would have said:
 
 10  x = x + 1 :  print x : goto 10
 
 run
 1
 2
 3
 etc
 

 How is this done in Python? (So I can stop holding my breath as I study 
 this great languageand relax.)

In Python there is no goto, as you have discovered. Loops are constructed using 
the 'for' and 'while' statements.

A while loop will loop as long as its condition is true. If you give it a 
condition that is always true, it will create an infinite loop like yours 
above. So the equivalent Python code would be

x=0
while True:
  x = x + 1
  print x

You can read a little more about while loops here and in the next chapter of 
your book:
http://docs.python.org/tut/node5.html#SECTION00520

Now relax and forget all the bad habits from you BASIC days ;-)

Kent

-- 
http://www.kentsjohnson.com

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie Anxiety

2005-11-10 Thread Roel Schroeven
Terry Kemmerer wrote:
 I'm working on Ch. 5, Fruitful Functions, or How To Think Like A
 Computer Scientist and I still can't count.
 (Don't laugh! I can't play the violin either...)
 
 In Basic, I would have said:
 
 10  x = x + 1 :  print x : goto 10
 
 run
 1
 2
 3
 etc
 
 How is this done in Python? (So I can stop holding my breath as I study
 this great languageand relax.)

You need to choose the appropriate control structure. In this case you
need an infinite loop, which in Python is written as:

while True:
# do stuff...

Also, in Python you need to explicitly give x its initial value:

x = 0

In Python 'x = x + 1' can be written shorter as 'x += 1' (though 'x = x
+ 1') works too.

All together:

x = 0
while True:
x += 1
print x

HTH

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

Roel Schroeven

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie Anxiety

2005-11-10 Thread Chris F.A. Johnson
On Thu, 10 Nov 2005, Terry Kemmerer wrote:

 I'm working on Ch. 5, Fruitful Functions, or How To Think Like A
 Computer Scientist and I still can't count.
 (Don't laugh! I can't play the violin either...)

 In Basic, I would have said:

 10  x = x + 1 :  print x : goto 10

Good heavens! I never used GOTO, even on the C-64:

10 for n = 1 to 10
20 print n
25 rem n = 1 rem  remove first rem for infinite loop
30 next


 run
 1
 2
 3
 etc

 I don't know why, but this great UNKNOWN bothers me a lot. Maybe it is
 because it was the first thing I learned in Basic,
 back 20 years ago when I was actually a programmer  But I  think it
 goes toward visualizing how things are
 going flow and be constructed without line numbers and the venerable
 GOTO statement.

 How is this done in Python? (So I can stop holding my breath as I study
 this great languageand relax.)

n = 1
while n = 10:
   print n
   n = n + 1


Or:

for n in [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]:
   print n


Or:

for n in range(10):
   print n + 1


Etc..


-- 
 Chris F.A. Johnson http://cfaj.freeshell.org
 ==
 Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
 http://www.torfree.net/~chris/books/cfaj/ssr.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie Anxiety

2005-11-10 Thread Alan Gauld
 In Basic, I would have said:
 
 10  x = x + 1 :  print x : goto 10

Tsk, tsk, even in BASIC that's considered bad form :-)

10 FOR X =1 to 10 
20 PRINT X
30 NEXT

Would be the better BASIC form.

And as you've seen Python provides a close analog to 
that in its for loop.

for X in [1,2,3,4,5,6,7,8,9,10]: 
print X

OR

for X in range(1,11): 
print X

 goes toward visualizing how things are 
 going flow and be constructed without line numbers and the venerable
 GOTO statement. 

I discuss why this is a bad idea in the old version of my tutor, which 
compared Python to old style BASIC. You might find it helpful if you 
were weaned on BASIC.  You can still find the old site here:

http://www.freenetpages.co.uk/hp/alan.gauld/oldtutor/

Check out the Loops topic for the GOTO discussion.

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie Anxiety

2005-11-10 Thread Alan Gauld
 compared Python to old style BASIC. You might find it helpful if you 
 were weaned on BASIC.  You can still find the old site here:
 
 http://www.freenetpages.co.uk/hp/alan.gauld/oldtutor/
 
 Check out the Loops topic for the GOTO discussion.

Oops, so long since I looked at that version...
Its actually the Branching topic that discusses GOTO.

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie Anxiety

2005-11-10 Thread Liam Clarke-Hutchinson
Title: Message



Hi 
Terry,

Python 
is great, very much so if the last you used was Basic.

I 
highly recommend Alan Gauld's tutorial, but I look forward to your queries here. 
:-)
Liam 
Clarke-Hutchinson
-Original Message-From: 
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of 
Terry KemmererSent: Friday, 11 November 2005 12:25 
p.m.To: Python_TUTORSubject: [Tutor] Newbie 
Anxiety
(I accidentally sent this to the 
  originator. Sorry.)Sweet! Almost everything is sooo 
  familiar, yet, merged in many interesting ways. I never had a DO WHILE 
  statement, but in many ways, your further examples are like a combination 
  of my old FOR NEXT loop and IF logical evaluation statement put together for 
  reading in/out lists. JUST TOO COOL! And it looks so CLEAN! 
  --compared to my old BASIC of having to name the variable belonging to each 
  NEXT incrementation executed while keeping the code nested properly relative 
  to each FOR NEXT loop!!!Thanks! THIS LOOKS 
  GREAT!TerryOn Fri, 2005-11-11 at 11:49 +1300, John 
  Fouhy wrote: 
  On 11/11/05, Terry Kemmerer [EMAIL PROTECTED] wrote:
  I'm working on Ch. 5, "Fruitful Functions", or "How To Think Like A
 Computer Scientist" and I still can't count.
  (Don't laugh! I can't play the violin either...)

  In Basic, I would have said:

  10  x = x + 1 :  print x : goto 10

  run
  1
  2
  3
  etc

  How is this done in Python? (So I can stop holding my breath as I study
 this great languageand relax.)

Hi Terry,

There's a couple of options.

First, we could do it with a while loop.  This is not the best or the
most idiomatic way, but it's probably most similar to what you've seen
before.

 count forever
i = 0
while True:
print i
i = i + 1


Of course, we generally don't want to keep counting forever.  Maybe
we'll count up to 9.

 count to 9
i = 0
while i  10::
print i
i = i + 1


A while loop contains an implicit "GOTO start" at the end.  At the
start, it checks the condition, and breaks out of the loop if the
condition is false.

Like i said, though, this is not idiomatic Python.  Python has for
loops which are based around the idea of iterating over a sequence. 
So, we could count to 9 like this:

 count to 9
for i in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
print i


The loop will go through the list, assigning each item to i in turn,
until the list is exhausted.  The range() function is useful for
building lists like that, so we don't have to type it out manually.

 count to 9
for i in range(10):
print i


And, of course, once we've got range(), we can give it a variable
limit (eg, n = 10; range(n)).  Iteration is the key to doing all kinds
of funky stuff in python (including new ideas like geneartor
functions), so it's good to get the hang of :-)

--
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


A new monthly electronic newsletter covering all aspects of MED's work is 
now available. Subscribers can choose to receive news from any or all of 
seven categories, free of charge: Growth and Innovation, Strategic Directions, 
Energy and Resources, Business News, ICT, Consumer Issues and Tourism. See 
http://news.business.govt.nz 
for more details.





govt.nz- connecting you to New 
Zealand central  local government services


Any opinions expressed in this message are not necessarily those of the Ministry 
of Economic Development. This message and any files transmitted with it are 
confidential and solely for the use of the intended recipient. If you are not 
the intended recipient or the person responsible for delivery to the intended 
recipient, be advised that you have received this message in error and that any 
use is strictly prohibited. Please contact the sender and delete the message and 
any attachment from your computer. 






___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor