Advertisement
ALEXANDAR_GEORGIEV

functions

Jun 13th, 2022
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. def check_prime(num):
  2.     count = 0
  3.     for i in range(1, num + 1):
  4.         if not num % i:
  5.             count += 1
  6.     if num == 1:
  7.         print(f'number {num} is Prime')
  8.     elif num > 1 and count == 2:
  9.         print(f'number {num} is Prime')
  10.     else:
  11.         print(f'number {num} is nonPrime')
  12.  
  13.  
  14. number = None
  15. while number != 'end':
  16.     number = int(input())
  17.     check_prime(number)
  18.  
  19. ###########################################
  20.  
  21. def check_prime(num):
  22.     count = 0
  23.     # global i
  24.     ch_p = False
  25.     for i in range(1, num + 1):
  26.         if not num % i:
  27.             count += 1
  28.     if num == 1:
  29.         ch_p = True
  30.     elif num > 1 and count == 2:
  31.         ch_p = True
  32.     else:
  33.         ch_p = False
  34.     return ch_p
  35.  
  36.  
  37. number = None
  38. while number != 'end':
  39.     number = int(input())
  40.     for i in range(1, number + 1):
  41.         number = str(number)
  42.         if len(number) == 1:
  43.             number = int(number)
  44.             check_prime(number)
  45.         else:
  46.             number = int(number)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement