Check for Prime Number either between 1-100 or user-given
- # def prime_checker(number):
- # for i in range(2, number):
- # if number % 1 == 0 and number % i == 0:
- # print(F"{number} is not Prime number")
- # break
- # else:
- # print(F"{number} is Prime number")
- # Other of doing above function
- def prime_checker(number):
- is_prime = True
- for i in range(2, number):
- if number % i == 0:
- is_prime = False
- if is_prime:
- print(F"{number}", end=' ')
- # else:
- # print(F"{number} is not Prime number")
- # n = int(input("Check this number: ")
- print("Prime number between 1 - 100", end='\n')
- for i in range(1, 101):
- prime_checker(i)
Output :
Prime number between 1 - 100
1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
Process finished with exit code 0
Comments
Post a Comment