Skip to content

Instantly share code, notes, and snippets.

@rostyq
Created July 30, 2017 10:41
Show Gist options
  • Save rostyq/02d5584823de4a2593305983a6f09659 to your computer and use it in GitHub Desktop.
Save rostyq/02d5584823de4a2593305983a6f09659 to your computer and use it in GitHub Desktop.
def get_user_int(msg):
'''
Return integer from user.
:param msg:
:return user_input:
'''
user_input = input(msg)
try:
user_input = int(user_input)
except:
print("Something wrong...")
return user_input
num = get_user_int("Input a number: ")
rng = range(1,num + 1)
new_rng = [i for i in rng if num % i == 0]
if len(new_rng) == 2:
print("Entered number is prime.")
else:
print("Entered number is not prime.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment