Logo
Explore Help
Register Sign In
TheAlgorithms/Python
1
0
Fork 0
You've already forked Python
Code Issues Pull Requests Actions 2 Packages Projects Releases Wiki Activity
Files
b566055e4b660b75a69577cac9dc1704667d7f3c
Python/maths/PrimeCheck.py

18 lines
347 B
Python
Raw Normal View History

Added a new Algorithm to check if a number is prime or not. (#487) * Added a new Algorithm to check if a number is prime or not. Added a new Algorithm to check if a number is prime or not. It takes one + half the amount of iterations of the square root of the number. Returns Boolean value. * Fixed possibility of being truncated Changed the 1/2 with a 0.5 * Fixed Major Error Instead of 3, 5, 7 The Loop as checking 2, 4, 6 which would cause all odd numbers to show prime. Fixed by subtracting one. * Fixed Minor Formatting issues Github Merged the 2 previous and current version to make a weird file. * Fixed possibility of being truncated Changed the 1/2 with a 0.5
2018-10-19 22:45:53 +05:30
def primeCheck(number):
prime = True
for i in range(2, int(number**(0.5)+1), 2):
if i != 2:
i = i - 1
if number % i == 0:
prime = False
break
return prime
def main():
print(primeCheck(37))
print(primeCheck(100))
print(primeCheck(77))
if __name__ == '__main__':
main()
Reference in New Issue Copy Permalink
Powered by Gitea Version: 1.24.6 Page: 96ms Template: 2ms
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어
Licenses API