TypeError: range() integer end argument expected, got str In Python
21,032
raw_input() returns a string.
Try this code:
first = int(raw_input("Enter the first no:"))
second = int(raw_input("Enter Second no:"))
And are you sure, that for i in range(2, i):
shouldn't be for i in range(2, x):
?
Comments
-
Om Prakash over 4 years
I am new and trying my hands on python. I wrote a program in python and when I execute I get errors. Can anyone please help me?
Program:
first = raw_input("Enter the first no:") second = raw_input("Enter Second no:") if first <= 0: print "Enter a valid number" if second <= first: print "Sencond number should be greater than first" for x in range(first,second): for i in range(2, i): if x % i == 0: j = x/i print x, " is not a prime no" print "%d = %d*%d" % (x, i, j) break; else: print x, " is not a prime number"
Input and error:
Enter the first no:1 Enter Second no:9 Traceback (most recent call last): File "today1.py", line 7, in <module> for x in range(first,second): TypeError: range() integer end argument expected, got str.
Thank you in advance.
-
Om Prakash over 10 yearsThanks Max, It worked. And yes, that would be x, not i. cheers. :)
-
Om Prakash over 10 yearsHey Max...I don't have that much reputation to like a post. So, I hope you understand. I am really thankful.