def is_prime(number):
Function Definition:
This line defines a function named is_prime that takes a parameter number. The function will return True if the number is prime and False otherwise.
Check for Numbers Less than 2:
This block of code checks if the input number is less than 2. If so, it immediately returns False since prime numbers are defined as greater than 1.
Check for Factors:
This loop checks for factors of the number from 2 up to the square root of the number. If any factor is found, the function returns False since the number is not prime.
Return True for Prime Numbers:
If the loop completes without finding any factors, the function returns True, indicating that the number is prime.
User Input:
This line prompts the user to enter a number for prime checking.
Function Call and Output:
This block of code calls the is_prime function with the user-provided number and prints the result based on whether the number is prime or not.
No comments:
Post a Comment