It's a simple Python program to find the number of primes until a certain number.

The for z in range(1,y): loop does not execute, but rather execution jumps to the print(count," Pr...) statement after the for loop.

The Python code -

    def bench(x):
    count = 0
    if x >= 2:
        count += 1
        for i in range(3,n + 1,2):
            count += 1
            for i in range(3,i*i <= p,2):
                if p%i == 0:
                    count -= 1
    return count
print("Recommended Load Value 1 - 3")
import time
while True:
    x = float(input("Enter Load Value: "))
    x = x * 10000000
    y = int(input("Enter Repeat Count: "))
    input("Press Enter to Run")

    for z in range(1,y):
        start = time.process_time()
        count = bench(x)
        t = time.process_time() - start
        total += t

    print(count," Primes processed.\n\nAverage time taken = ","{:.4f}".format(total/y))
    loop = input(" Re-Run ? (Y/N) : ")
    if loop == 'n' or loop == 'N':
        input("Press Enter to Exit")

If y is 1, the z loop doesn't run. From w3schools:

The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and stops before a specified number.

Error will come in the print because total is never defined/declared.

For y > 1 name error will come in bench function because n is never defined/declared. Once that is fixed, error will come here total += t, again because total is never defined/declared.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .