-
Notifications
You must be signed in to change notification settings - Fork 0
/
Coding challenge: 02
22 lines (21 loc) · 1.06 KB
/
Coding challenge: 02
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Primality Test
# Alice and Bob are meeting after a long time. As usual they love to play some math games.
# This times Alice takes the call and decides the game.
# The game is very simple, Alice says out an integer and Bob has to say whether the number is prime or not.
# Bob as usual knows the logic but since Alice doesn't give Bob much time to think, so Bob decides to write a computer program.
# Help Bob accomplish this task by writing a computer program which will calculate whether the number is prime or not .
# Input: The first line of the input contains an integer T, the number of testcases. T lines follow.
# Each of the next T lines contains an integer N which has to be tested for primality.
# Output: For each test case output in a separate line, "yes" if the number is prime else "no."
# Determine if n is prime.
# Returns true or false
# n should be positive and an integer
def isPrime(n):
strInt = str(n)
l = len(strInt)
if n <= 1:
return False
for divisor in range(2,n):
if n%divisor == 0:
return False
return True