Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update P07_PrimeNumber.py #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

VittalKumar23
Copy link

Assuming the Number is Prime by Default:

The variable isPrime is initially set to True by default. This is a fundamental change from the original code, which assumed the number was not prime by default (isPrime = False). In primality testing, it's typically better to assume the number is prime until proven composite.
Input Validation:

The code checks if the input number number is greater than 1 before proceeding with prime checking. This step ensures that the input is a positive integer, as prime numbers are defined as greater than 1.
Iterating Through Potential Divisors:

A for loop iterates through numbers from 2 to number - 1. These are the potential divisors that are checked to see if they divide the input number evenly (i.e., number % i == 0).
Checking for Divisibility:

Inside the loop, the code checks if the current i evenly divides the input number (number % i == 0). If this condition is true, it means the input number is divisible by i, and therefore, it's not a prime number.
If divisibility is found, isPrime is set to False, indicating that the input number is not prime, and the loop is terminated using break.
Printing the Result:

After the loop finishes, the code prints the result based on the value of isPrime. If isPrime remains True after the loop, it means that the input number is not divisible by any of the numbers in the loop, making it prime. In this case, it prints that the number is prime.
If isPrime was set to `False during the loop, it indicates that the input number is divisible by at least one of the numbers in the loop, making it composite. In this case, it prints that the number is not prime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant