Python Forum
i want to know the difference - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: i want to know the difference (/thread-41485.html)



i want to know the difference - Naisuke - Jan-23-2024

a=int(input("enter a number:"))
def check_prime_numbers():
    for i in range(2, (a//2+1)):
        if a%i==0  :
            print(f"{a} isn't prime number")
            break
    else:
        print(f"{a} is a prime number")
check_prime_numbers()
my teach send me this code and asked me why did he printed a instead of i
can I get some help?


RE: i want to know the difference - deanhystad - Jan-23-2024

Do you know what the code does?


RE: i want to know the difference - Naisuke - Jan-24-2024

(Jan-23-2024, 04:14 PM)deanhystad Wrote: Do you know what the code does?
it is use to find prime numbers


RE: i want to know the difference - deanhystad - Jan-24-2024

Not really. It checks if a number is prime. A subtle, but important difference. What role does "a" play? Is it the potential prime number, or a potential factor?

The code is poorly written. "a" should be passed as a function argument, not as a global variable. The function should return a value instead of printing a message.