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 Prime or not #2966

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions python-programming-2/Prime or not
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
# Program to check if a number is prime or not

num = 407
# Take input from the user
num = int(input("Enter a number: "))

# To take input from the user
#num = int(input("Enter a number: "))

# prime numbers are greater than 1
# Prime numbers are greater than 1
if num > 1:
# check for factors
for i in range(2,num):
if (num % i) == 0:
print(num,"is not a prime number")
print(i,"times",num//i,"is",num)
break
else:
print(num,"is a prime number")

# if input number is less than
# or equal to 1, it is not prime
# Check for factors only up to the square root of num
for i in range(2, int(num**0.5) + 1):
if (num % i) == 0:
print(num, "is not a prime number")
print(i, "times", num // i, "is", num)
break
else:
print(num, "is a prime number")
else:
print(num,"is not a prime number")
print(num, "is not a prime number")