bobhig

Prime

May 20th, 2021
680
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Code to test if a number is prime based on pseudocode but with any integer input
  2. #number <-- 17
  3. #prime <-- TRUE
  4. #
  5. #FOR i <-- 2 TO number
  6. #    IF number is divisible by i THEN
  7. #        prime <-- FALSE
  8. #
  9. #IF prime = TRUE:
  10. #    OUTPUT "prime"
  11. #ELSE
  12. #    OUTPUT "not prime"
  13.  
  14. number = input("Enter any whole number ")
  15. prime = True
  16.  
  17. #convert from string to integer
  18. number = int(number)
  19.  
  20. for i in range(2,number):
  21.     if number % i == 0:
  22.         prime = False
  23.  
  24. if prime == True:
  25.     print(str(number) +  " is prime")
  26. else:
  27.     print(str(number) +  " is not prime")
RAW Paste Data