我是新的,並試圖在我的手在python上。 我用python編寫了一個程序,當我執行的時候出現錯誤。誰能幫幫我嗎?TypeError:range()整數結束參數期望,得到str在Python中
計劃:
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"
輸入和錯誤:
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.
預先感謝您。
好吧,從標準輸入您得到字符串,而不是數字。你必須轉換它們。 (想到'int()') – Ronald