---
title: "Create a program to determine if a number is prime or not."  
description: "Create a program to determine if a number is prime or not."  
author: "Steilla Mitchel"  
published: 2023-06-18  
updated: 2023-06-19  
canonical: https://www.mindstick.com/forum/158761/create-a-program-to-determine-if-a-number-is-prime-or-not  
category: "python"  
tags: ["python", "programs"]  
reading_time: 2 minutes  

---

# Create a program to determine if a number is prime or not.

Create a [program to determine](https://www.mindstick.com/forum/158797/create-a-rust-program-to-determine-if-a-number-is-prime-or-not) if a number is prime or not.

## Replies

### Reply by Aryan Kumar

Sure, here is a Python [program](https://www.mindstick.com/blog/12337/scaling-up-your-mentorship-program) to determine if a number is prime or not:

Python

```plaintext
def is_prime(number):
  """
  Determines if a number is prime or not.

  Args:
    number: The number to check if it is prime.

  Returns:
    True if the number is prime, False otherwise.
  """

  if number <= 1:
    return False

  for i in range(2, int(number ** 0.5) + 1):
    if number % i == 0:
      return False

  return True

if __name__ == "__main__":
  number = 11
  is_prime_number = is_prime(number)
  print(is_prime_number)
```

This program works by first checking if the number is less than or equal to 1. If it is, then the program returns False.

Otherwise, the program iterates through the numbers from 2 to the square root of the number and checks if the number is divisible by any of the numbers. If the number is divisible by any of the numbers, then the program returns False. Finally, the program returns True.

To run the program, you can save it as a Python file and then run it from the command line. For example, if you save the program as `is_prime.py`, you can run it by typing the following command into the command line:

Code snippet

```plaintext
python is_prime.py
```

This will print the boolean value of whether the number is prime to the console.

Here is an example of the output of the program:

Code snippet

```plaintext
$ python is_prime.py
True
```

As you can see, the output of the program is True, which means that the number is a prime number.


---

Original Source: https://www.mindstick.com/forum/158761/create-a-program-to-determine-if-a-number-is-prime-or-not

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
