dumb newbie questions

nate nathanhewat at yahoo.com
Thu Jan 17 19:53:41 CET 2002


I'm trying to teach myself Python using 'Learning Python' by Lutz and
Ascher.  I hope nobody's offended by the trivial nature of my
questions.  As you can probably tell, I have no previous coding
experience and so would appreciate any constructive critisism.

I'm aware that the numeric extension to python probably has everything
I need, but would prefer to master the basics and learn to code the
things numPy does, before I use the tools it contains (...and partly
to brush up on Linear Algebra)

I'm currently stuck (at the beginning, dammit!) on this piece of code
to manually enter a matrix...

import sys
print 'enter the no. of rows'
print 'enter the no. of columns'
print 'a',row,'x',col,'matrix has been entered' 
# I want it to print: 'a row x col matrix... '
# but it prints a newline after each number (row and col).
# there were no problems with it at the interactive prompt.
while i<=row:
	while j<=col:
		print 'enter the', i, j, '-th element'
		j=j+1; continue 
# What am I doing wrong with this loop? - it fails to move on when
j>col, and
# returns 'enter the 1 <nth> -th element' to infinity (?!?)
# I tried using for loops eg: 'for j in range(col):' Why can I not use
col with
# range? 
		i=i+1; break
	print 'the matrix you have entered is...'
	for rows in matrix:
		print rows
		print '\nfinished'
I think the rest of it's ok... If you respond to this please be
careful to say it slow, so I can understand ;o). Cheers

More information about the Python-list mailing list