dumb newbie questions

Andrew Koenig ark at research.att.com
Thu Jan 17 14:28:21 EST 2002


nate> import sys
nate> print 'enter the no. of rows'
nate> row=sys.stdin.readline()
nate> print 'enter the no. of columns'
nate> col=sys.stdin.readline()
nate> print 'a',row,'x',col,'matrix has been entered' 
nate> # 
nate> # I want it to print: 'a row x col matrix... '
nate> # but it prints a newline after each number (row and col).
nate> # there were no problems with it at the interactive prompt.
nate> #

The readline function returns the entire input line as a string,
including the newline at the end.  That's not what you want -- you
want to convert the line to an integer.  To do so, write

        row=int(sys.stdin.readline())

and similarly for col.

-- 
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark



More information about the Python-list mailing list