-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
980464d
commit 4039386
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |