Learning question...

Terry Reedy tjreedy at udel.edu
Wed May 7 15:15:55 EDT 2008


<swapsun at gmail.com> wrote in message 
news:d61b9c56-6f9a-4b29-9247-4fce0b80ecbe at f63g2000hsf.googlegroups.com...
| Any idea why the following program does not work? I was learning IO on
| Python and the following generates a TypeError: range() integer end
| argument expected, got str.
| I am a beginner.
|
| ################################
| # print input name (str k), j times using raw_input
|
| def hello():
|    j=raw_input("Please type in the number of times you want to print
| ")
|    k=raw_input("Please type in your name ")
|    printname(j,k)
|
| def printname(j,k):
|          for i in range(j):
|                print ("Hello %s" % k)

For future debugging, use print to find out what values you actually have.
print j,k #before printname()
would have shown you that j is a string.
Also use the type() function as needed.
And do read the Lib Ref sections on builting functions and types.

tjr








More information about the Python-list mailing list