Created
July 31, 2017 20:39
-
-
Save jgarciabu/09465ac9c64133577a9c098e1327c04f to your computer and use it in GitHub Desktop.
Is Prime Ex 11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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