Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a Branch #5

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
19 changes: 12 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
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):
'''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;
x = math.sqrt(num)
if x - int(x) == 0:
return x


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

if __name__ == "__main__":
main()
main()
18 changes: 15 additions & 3 deletions main2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,27 @@ 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):
'''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
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():
Expand All @@ -23,4 +35,4 @@ def main():
# Add any additional test cases if needed

if __name__ == "__main__":
main()
main()