Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,47 @@
def hello_world():
'''Prints "Hello World!".'''
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
sum = 0
for i in range(a):
sum += b
return sum



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
quotient = 0
for x in range(a, 0, b * (-1)):
quotient += 1
return quotient


def root(num):
'''Accepts a number as a parameter, returns the sqrt of 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;
if (num == 0 | num == 1):
return num
for x in range(2, num):
if (x*x >= num):
break

return x


def main():
Expand All @@ -50,4 +60,4 @@ def main():
# Add any additional test cases if needed

if __name__ == "__main__":
main()
main()
27 changes: 23 additions & 4 deletions main2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,41 @@ 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 []
output = []
for x in nums:
if (x % 2 == 0):
output.append(1)
else:
output.append(0)
return output


def mostOccurences(nums):
'''Given an unsorted list of numbers, returns the value that occured the most in 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

occurences = {}
for x in nums:
if (x in occurences):
occurences[x] += 1
else:
occurences[x] = 1

number = -1
maximum = 0
for index in occurences:
if (occurences[index] > maximum):
number = index
maximum = occurences[index]

return number

def main():
'''The main function is where you will test all of your functions.'''
# Testing challenge 2
print("\nTesting oddOrEven")
print("EXPECTED:", [1, 1, 0, 0, 1, 1], "\nACTUAL:", oddOrEven([2, 4, 5, 7, 8, 10]))
print("EXPECTED:", [1, 1, 0, 0, 1, 1], '\nACTUAL:', oddOrEven([2, 4, 5, 7, 8, 10]))
print("\nTesting mostOccurences")
print("EXPECTED:", 1, "\nACTUAL:", mostOccurences(oddOrEven([2, 4, 5, 7, 8, 10])))
# Add any additional test cases if needed
Expand Down