Guest User

Untitled

a guest
Apr 26th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. # Ask the user for a number and determine whether the number is prime or not. (For those who have
  2. # forgotten, a prime number is a number that has no divisors.). You can (and should!) use your
  3. # answer to Exercise 4 to help you. Take this opportunity to practice using functions, described below.
  4.  
  5. num = int(input("Please enter a number to test for primality: "))
  6.  
  7. def primecheck(int):
  8. list = range(2, int)
  9. output = [x for x in list if int % x == 0]
  10. if not output:
  11. print("Your number is a prime!")
  12. else:
  13. print("Your number is not a prime!")
  14.  
  15. primecheck(num)
Add Comment
Please, Sign In to add comment