Skip to main content
deleted 18 characters in body
Source Link
Daniel
  • 4.5k
  • 2
  • 17
  • 40

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:

    1. A comma , should be followed by a [space], for readability;
    2. A modulo operator, as well as other mathematical operators, should be preceded by and followed by a [space];
    3. A range() call (or any other function call), should not be followed by a [space] before the first argument;
  • Use i += 1 instead of i = 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

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:

    1. A comma , should be followed by a [space], for readability;
    2. A modulo operator, as well as other mathematical operators, should be preceded by and followed by a [space];
    3. A range() call (or any other function call), should not be followed by a [space] before the first argument;
  • Use i += 1 instead of i = i + 1;

  • Calling print without " " will also print -nothing-.

Rewritten

while True:
    x = raw_input("Input a number: ")
    try:
        x = int(x)
        break
    except ValueError:
        print("Input must be a number!")

for i in range(x):
    a = map(int, raw_input().split())
    if a[0] == 1:
        a[0] = 2
    for num in range(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

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:

    1. A comma , should be followed by a [space], for readability;
    2. A modulo operator, as well as other mathematical operators, should be preceded by and followed by a [space];
    3. A range() call (or any other function call), should not be followed by a [space] before the first argument;
  • Use i += 1 instead of i = i + 1;

  • Calling print without " " will also print -nothing-.

Rewritten

while True:
    x = raw_input("Input a number: ")
    if not x.isdigit():
        print("Input must be a number!")
        continue
    break

for i in xrange(x):
    a = map(int, raw_input().split())
    if a[0] == 1:
        a[0] = 2
    for num in xrange(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
Element is not a good description > argument
Source Link
Daniel
  • 4.5k
  • 2
  • 17
  • 40

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:

    1. A comma , should be followed by a [space], for readability;
    2. A modulo operator, as well as other mathematical operators, should be preceded by and followed by a [space];
    3. A range() call (or any other function call), should not be followed by a [space] before the first element;argument;
  • Use i += 1 instead of i = i + 1;

  • Calling print without " " will also print -nothing-.

Rewritten

while True:
    x = raw_input("Input a number: ")
    try:
        x = int(x)
        break
    except ValueError:
        print("Input must be a number!")

for i in range(x):
    a = map(int, raw_input().split())
    if a[0] == 1:
        a[0] = 2
    for num in range(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

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:

    1. A comma , should be followed by a [space], for readability;
    2. A modulo operator, as well as other mathematical operators, should be preceded by and followed by a [space];
    3. A range() call (or any other function call), should not be followed by a [space] before the first element;
  • Use i += 1 instead of i = i + 1;

  • Calling print without " " will also print -nothing-.

Rewritten

while True:
    x = raw_input("Input a number: ")
    try:
        x = int(x)
        break
    except ValueError:
        print("Input must be a number!")

for i in range(x):
    a = map(int, raw_input().split())
    if a[0] == 1:
        a[0] = 2
    for num in range(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

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:

    1. A comma , should be followed by a [space], for readability;
    2. A modulo operator, as well as other mathematical operators, should be preceded by and followed by a [space];
    3. A range() call (or any other function call), should not be followed by a [space] before the first argument;
  • Use i += 1 instead of i = i + 1;

  • Calling print without " " will also print -nothing-.

Rewritten

while True:
    x = raw_input("Input a number: ")
    try:
        x = int(x)
        break
    except ValueError:
        print("Input must be a number!")

for i in range(x):
    a = map(int, raw_input().split())
    if a[0] == 1:
        a[0] = 2
    for num in range(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
Source Link
Daniel
  • 4.5k
  • 2
  • 17
  • 40

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:

    1. A comma , should be followed by a [space], for readability;
    2. A modulo operator, as well as other mathematical operators, should be preceded by and followed by a [space];
    3. A range() call (or any other function call), should not be followed by a [space] before the first element;
  • Use i += 1 instead of i = i + 1;

  • Calling print without " " will also print -nothing-.

Rewritten

while True:
    x = raw_input("Input a number: ")
    try:
        x = int(x)
        break
    except ValueError:
        print("Input must be a number!")

for i in range(x):
    a = map(int, raw_input().split())
    if a[0] == 1:
        a[0] = 2
    for num in range(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