Skip to content

Instantly share code, notes, and snippets.

@Raj39120
Created April 30, 2020 13:43
Show Gist options
  • Save Raj39120/373d81efe3405935bb7430bc462ba221 to your computer and use it in GitHub Desktop.
Save Raj39120/373d81efe3405935bb7430bc462ba221 to your computer and use it in GitHub Desktop.
def prime_number():
print("This program determines if a number is prime or not.")
print("This program will only accept integers.")
number = input("Please enter the number you want to check over here: ")
number = int(number)
if number > 0:
if number == 3:
print("The number is prime.")
choice = input("Do you want to enter another number? Type 'continue' if you do & 'exit' if you don't: ")
if choice == 'continue':
prime_number()
if choice == 'exit':
return
if choice != 'continue' and choice != 'exit':
print("You have not entered a valid choice so the program will stop running.")
return
if number == 1:
print("One is neither prime nor composite.")
choice = input("Do you want to enter another number? Type 'continue' if you do & 'exit' if you don't: ")
if choice == 'continue':
prime_number()
if choice == 'exit':
return
if choice != 'continue' and choice != 'exit':
print("You have not entered a valid choice so the program will stop running.")
return
if number == 2:
print("The number is prime.")
choice = input("Do you want to enter another number? Type 'continue' if you do & 'exit' if you don't: ")
if choice == 'continue':
prime_number()
if choice == 'exit':
return
if choice != 'continue' and choice != 'exit':
print("You have not entered a valid choice so the program will stop running.")
return
for x in range(2, number - 1):
if number % x != 0:
continue
elif number % x == 0:
print("The number is not prime.")
choice = input("Do you want to enter another number? Type 'continue' if you do & 'exit' if you don't: ")
if choice == 'continue':
prime_number()
if choice == 'exit':
return
if choice != 'continue' and choice != 'exit':
print("You have not entered a valid choice so the program will stop running.")
return
else:
print("The number is prime.")
choice = input("Do you want to enter another number? Type 'continue' if you do & 'exit' if you don't: ")
if choice == 'continue':
prime_number()
if choice == 'exit':
return
if choice != 'continue' and choice != 'exit':
print("You have not entered a valid choice so the program will stop running.")
return
elif number == 0:
print("Zero is neither prime nor composite.")
choice = input("Do you want to enter another number? Type 'continue' if you do & 'exit' if you don't: ")
if choice == 'continue':
prime_number()
if choice == 'exit':
return
if choice != 'continue' and choice != 'exit':
print("You have not entered a valid choice so the program will stop running.")
return
if number < 0:
print("This number is less than 0. Please enter a positive integer next time.")
return
prime_number()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment