Learning question...
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) -- http://mail.python.org/mailman/listinfo/python-list
Re: Learning question...
On May 7, 8:36 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > 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. > > Because raw_input does return you as string which you need explicitly > convert to a number, e.g. doing > > i = int(input) > > Diez Thank you, Diez! -- http://mail.python.org/mailman/listinfo/python-list
Re: Learning question...
On May 7, 8:42 am, Thomas Woelz <[EMAIL PROTECTED]> wrote: > On 7 maio, 09:25, [EMAIL PROTECTED] wrote: > > > 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 ") > > # add this: > j = int(j) > > > printname(j,k) > > > def printname(j,k): > > for i in range(j): > > print ("Hello %s" % k) > > > > theres too much whitespace in the printname function, try to stick > with 4 spaces (and no tabs) for each block Thanks very much for the advice. Will follow... -- http://mail.python.org/mailman/listinfo/python-list