Write a Python function that takes a number as a parameter and check the number is prime or not


Introduction

Write a Python function that takes a number as a parameter and check the number is prime or not. I have used python 3.7 compiler for debugging purpose.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. def test_prime(num):
  2. if (num==1):
  3. return False
  4. elif (num==2):
  5. return True;
  6. else:
  7. for x in range(2, num):
  8. if(num % x==0):
  9. return False
  10. return True
  11. print(test_prime(167))

Result

python language techstudy.org

     





Related Topics




Popular Posts