-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYou're_a_square!_kyu7.py
43 lines (38 loc) · 1.03 KB
/
You're_a_square!_kyu7.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# # A function that works out if any given number is a square number
# Various previous attempts
# Import math
# If statement that ensures we're only working with positive numbers
# Variable that temporarily stores the square root of n
# Forces the square root to be an int and times is by itself to work out if n is a square number
import math
def is_square(n):
# squares = []
# ranges = range(0,999)
# for number in ranges:
# squares += ([number * number])
# print(n)
# if n in squares:
# return True
# elif n < 0:
# return False
# else:
# return False
# if n < 0:
# return False
# if n >= 0:
# root = math.sqrt(n)
# root_type = type(root)
# print(root)
# print(root_type)
# if root_type is int:
# return True
# else:
# return False
if n < 0:
return False
if n >= 0:
root = math.sqrt(n)
if int(root) * int(root) == n:
return True
else:
return False