Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. # Exercise nr. 11 from practicepython.org
  2.  
  3. def get_int(input_text="Enter a number: "):
  4.     while True:
  5.         try:
  6.             return int(input(input_text))
  7.             break
  8.         except ValueError:
  9.             print("Use a valid number!")
  10.  
  11.  
  12. def is_priem(getal):
  13.     l = list(range(1,getal+1))
  14.     if len([div for div in l if getal%div == 0]) == 2:
  15.         print("%d is a prime"%getal)
  16.     else:
  17.         print("%d is not a prime"%getal)
  18.  
  19. def try_again():
  20.     while True:
  21.         inp=input("Do u want to try again? (y/n): " )
  22.         if (c:= inp.lower()) == "n" or c=="no" :
  23.             return False
  24.             break
  25.         elif c == "y" or c =="yes":
  26.             return True
  27.             break
  28.         else:
  29.             print("I'm not sure what you mean.. please answer with yes or no")
  30.  
  31.  
  32.  
  33. cont=True
  34. while cont == True:
  35.     is_priem(get_int())
  36.     cont=try_again()
  37.  
  38.  
  39. print("Goodbye!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement