diff --git a/main.py b/main.py index 379f286..0e9d269 100644 --- a/main.py +++ b/main.py @@ -1,29 +1,32 @@ +import math def hello_world(): '''Prints "Hello World!".''' - return + print("Hello World") + return def sum(a, b): '''Accepts 2 numbers as parameters, returns sum of a and b.''' - return 0 + return a + b def sub(a, b): '''Accepts 2 numbers as parameters, returns subtraction of a and b.''' - return 0 + return a - b def product(a, b): '''Accepts 2 numbers as parameters, returns product of a and b.''' # CHALLENGE: use a for loop and your sum function to implement product - return 0 + return a * b def divide(a, b): '''Accepts 2 numbers as parameters, returns a divided by b.''' # only pass in numbers that are divisible for sake of implementation # CHALLENGE: use a while loop and your sub function to implement divide - return 0 + if b != 0: + return a/b def root(num): @@ -31,7 +34,9 @@ def root(num): # only pass in numbers that are perfect squares for sake of implementation # leetcode easy # CHALLENGE: do not use any built-in Python functions - return 0; + x = math.sqrt(num) + if x - int(x) == 0: + return x def main(): @@ -50,4 +55,4 @@ def main(): # Add any additional test cases if needed if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/main2.py b/main2.py index 2f6ad21..ab38ce9 100644 --- a/main2.py +++ b/main2.py @@ -2,7 +2,13 @@ def oddOrEven(nums): '''Given an unsorted list of numbers, return a list that indicates if the value at each index is odd (0) or even (1).''' # EXAMPLE: # Given [2, 4, 5, 7, 8, 10], return [1, 1, 0, 0, 1, 1] - return [] + x = [] + for i in nums: + if i % 2 == 0: + x.append(1) + else: + x.append(0) + return x def mostOccurences(nums): @@ -10,7 +16,13 @@ def mostOccurences(nums): # Hint: use oddOrEven to test function faster # Hint: use a map # Hint: https://stackoverflow.com/questions/13098638/how-to-iterate-over-the-elements-of-a-map-in-python - return -1 + d = {} + for i in nums: + if i in d.keys(): + d[i] += 1 + else: + d[i] = 0 + return max(d, key=d.get) def main(): @@ -23,4 +35,4 @@ def main(): # Add any additional test cases if needed if __name__ == "__main__": - main() \ No newline at end of file + main()