Some quick things that caught my attention:
Your code does not handle exceptions, what if the user inputs "xyz" and the program raises a ValueError?
Some PEP-8 things:
- A comma
,
should be followed by a [space], for readability; - A modulo operator, as well as other mathematical operators, should be preceded by and followed by a [space];
- A
range()
call (or any other function call), should not be followed by a [space] before the first argument;
- A comma
Use
i += 1
instead ofi = i + 1
;Calling
print
without" "
will also print -nothing-.
Rewritten
while True:
x = raw_input("Input a number: ")
try:
if not x = int.isdigit(x):
break
print("Input must be excepta ValueError:number!")
print("Inputcontinue
must be a number!")break
for i in rangexrange(x):
a = map(int, raw_input().split())
if a[0] == 1:
a[0] = 2
for num in rangexrange(a[0], a[1]+1):
if num == 2:
print num
for j in range(2, num):
if num % j == 0:
break
elif j == num - 1:
print num
print
i += 1