Python Forum
i want to know the difference
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i want to know the difference
#1
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?
deanhystad write Jan-23-2024, 04:13 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
Do you know what the code does?
Reply
#3
(Jan-23-2024, 04:14 PM)deanhystad Wrote: Do you know what the code does?
it is use to find prime numbers
Reply
#4
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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020