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)
################################ 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
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
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!
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...
<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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
by: sudhakar.subbiah |
last post by:
I can learning c Language
|
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?...
|
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...
|
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,...
| |
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,...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |