Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: is_prime.py
- # Author: Jeoi Reqi
- """
- Is Prime Script
- This script checks whether a user-input number is a prime number or a negative prime.
- Negative primes are prime numbers that are less than zero. They have the same properties as positive primes but with a negative sign. Examples include -2, -3, -5, 7... etc.
- It utilizes a function, is_prime, to perform the prime number check.
- Requirements:
- - Python 3
- Usage:
- 1. Run the script.
- 2. Enter a number when prompted.
- 3. The script will display whether the entered number is a prime number, a
- negative prime, or not prime.
- """
- def is_prime(number):
- """Check if a number is a prime number.
- Args:
- number (int): Number.
- Returns:
- bool: True if number is a prime number, False otherwise.
- """
- if number < 2:
- return False
- for x in range(2, int(abs(number)**0.5) + 1):
- if abs(number) % x == 0:
- return False
- return True
- def main():
- # Get user input
- user_input = int(input("Enter a number: "))
- # Check if it's a negative prime
- if is_prime(abs(user_input)):
- if user_input < 0:
- print(f"The number {user_input} is a Negative Prime.")
- else:
- print(f"The number {user_input} is Prime.")
- else:
- print(f"The number {user_input} is Not Prime.")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement