0

I'm executing this code:

#Printing a list of prime numbers till an input number:
def is_prime(input):
    for counter1 in range(1,input):
        if(counter1==2):
            print("Prime number: 2")
        counter2=2
        while (counter1%counter2!=0 and counter2<counter1):
            if(counter2==(counter1-1)):
                print("Prime number:",counter1)
            counter2+=1

print("Let us print prime numbers upto 10:",is_prime(10))

OUTPUT:

Prime number: 2
Prime number: 3
Prime number: 5
Prime number: 7
Let us print prime numbers upto 10: None

Why "Prime numbers:" are printed first then the string "Let us..." ??

  • 1
    All argument values have to be resolved before calling a function, in this case that means the call to is_prime has to be complete before print gets called. – jonrsharpe May 06 '22 at 07:28
  • As @jonrsharpe said, you put the `is_prime(10)` into your print and is executed first. A function without a explecit return wil always return `None`, which then gets printed. – ivvija May 06 '22 at 07:36

0 Answers0