Skip to content

Instantly share code, notes, and snippets.

@jgarciabu
Created July 31, 2017 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgarciabu/09465ac9c64133577a9c098e1327c04f to your computer and use it in GitHub Desktop.
Save jgarciabu/09465ac9c64133577a9c098e1327c04f to your computer and use it in GitHub Desktop.
Is Prime Ex 11
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Ask the user for a number and determine whether the number is prime or not.
(For those who have forgotten, a prime number is a number that has
no divisors.). You can (and should!) use your answer to Exercise 4 to help you.
Take this opportunity to practice using functions, described below.
@author: Jeff Garcia
"""
def is_prime(help_text = "Please enter a number: "):
user = int(input(help_text))
if user > 2:
for i in range(2,user):
if (user % i) == 0:
print(user, " is not a prime number.")
print(i, " times" , user//i , " is" , user , ".")
break
else:
print(user, " is a prime number.")
else:
print(user, " is not a prime number.")
print(is_prime())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment