Question:
Invalid literal with integer() with base 10?
Dan
2012-07-28 18:51:17 UTC
I keep getting this result while I'm trying to program a number counter with python. Here is the code:


#Word Counter
#Practice using python
#Daniel Goldring 7/28/12
begin = raw_input (int('Enter the number you would like to begin with.'))
end = raw_input (int('Enter the number you would like to end with.'))
count = raw_input (int('Enter how many numbers you would like me to count at one time.'))
while begin:
begin + count
print begin
if begin == end:
break
print 'Welcome to word counter!'
print 'This program will count numbers for you instead of having to do it yourself.'
Three answers:
Ian
2012-07-28 19:07:53 UTC
instead of using raw_input() try just using input() and then converting it to int so

begin = int(input(text)) and in your while loop I think you mean begin+= count. Also just a heads up if the user ever types in 0 for begin then the while loop won't run, because Python considers 0 to evaluate to False and any other number to True so a better loop would be while True:



of course that is bad practice to set yourself up for an infinite loop, because for example, I could have us begin at 0 end at 5 and count by 4 and we would never hit the if begin== end being true. So you could change that to begin >= end (or you know put begin < end as your while loop condition)
James Bond
2012-07-29 01:55:34 UTC
Try like

begin =int( raw_input('Enter the number you would like to begin with.'))



Also check

begin + count



Also, you are using begin etc reserved or keywords as variable. change them
no1home2day
2012-07-29 01:55:12 UTC
Okay, I'm sorry that you keep getting that error message, but what's your question?


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...