473,504 Members | 13,601 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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)
################################
Jun 27 '08 #1
5 4125
sw*****@gmail.com 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
Jun 27 '08 #2
On 7 maio, 09:25, swap...@gmail.com 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
Jun 27 '08 #3
On May 7, 8:36*am, "Diez B. Roggisch" <de...@nospam.web.dewrote:
swap...@gmail.com 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!
Jun 27 '08 #4
On May 7, 8:42*am, Thomas Woelz <two...@gmail.comwrote:
On 7 maio, 09:25, swap...@gmail.com 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...
Jun 27 '08 #5

<sw*****@gmail.comwrote in message
news:d6**********************************@f63g2000 hsf.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

Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2587
by: post400 | last post by:
Hi , I was just wondering ( yeah I know it's not the first time this question pops up ) what would be the best 2 or 3 books for someone who wants to learn Python , already experienced in other...
1
1955
by: James White | last post by:
I have a young nephew who appears to be developing into a natural geek/nerd/guru/whatever and as he learns I need to make sure that he stays on the side of the white hats, rather than going down...
15
1985
by: John Salerno | last post by:
After my last post, I thought of another question as a result of the following: ------------------------------ Mike Meyer wrote: > John Salerno <johnjsal@NOSPAMgmail.com> writes: > > >>So...
4
1180
by: Ricky W. Hunt | last post by:
I have two mixed questions, sorry for the unclear subject line. I downloaded the Visual Basic Resource Kit from MS but I can't get it to work. I have WinXP Home so I don't know if that's part of...
1
9584
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
26
2928
by: mfasoccer | last post by:
I am sorry if this is an inappropriate place to put this post, if so please delete it. I am wondering about a few things. Do you guys recommend learning C as a second language, as someone who...
5
1759
by: romiro | last post by:
Hi all, I'm a PHP5 developer looking to "broaden my horizons" so to speak by learning a new language. I emphasize the 5 in PHP since I have fully engrossed myself in the full OOP of version 5...
13
1728
by: sudhakar.subbiah | last post by:
I can learning c Language
16
1739
by: John Salerno | last post by:
Just something that crosses my mind every time I delve into "Learning Python" each night. Does anyone see any value in learning Python when you don't need to for school, work, or any other reason?...
12
1579
by: Mitch | last post by:
I'm wondering if I'm doing myself a disservice by learning Visual C#, considering it does so much of the work behind the scenes. Should I be learning console apps first? I still haven't found...
0
7213
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7298
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4698
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
406
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.