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
Binary file added .DS_Store
Binary file not shown.
Empty file modified data/sales_records.csv
100644 → 100755
Empty file.
25 changes: 20 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,52 @@
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
ans = 0
for i in range(b):
ans = sum(ans, a)
return ans


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
ans = 0
while (a > 0):
a = sub(a, b)
ans += 1
return ans


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 or num == 1:
return num
ans = 1
result = 1
while (result < num):
ans += 1
result = ans * ans
return ans;


def main():
Expand Down
15 changes: 13 additions & 2 deletions main2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@ 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 []
return [(i + 1) % 2 for i in nums]


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
mp = {}
for k in nums:
if k in mp:
mp[k] += 1
else:
mp[k] = 1
max, ans = -1, 0
for i in mp:
if max < mp[i]:
max = mp[i]
ans = i
return ans


def main():
Expand Down
33 changes: 27 additions & 6 deletions main3.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,60 @@
#### INCLUDE ANY IMPORTS YOU NEED HERE, DO NOT PIP INSTALL ANY LIBRARIES ####
import statistics as stats
from math import sqrt
from random import randrange
from datetime import date
import csv


def perfect_square(num):
'''Return the sqrt of <num> only if <num> is a perfect square, otherwise return -1.'''
# Hint: math library
return 0
square_root = sqrt(num)
if int(square_root + 0.5) ** 2 == num:
return int(square_root)
return -1


def random_num_generator(min, max):
'''Returns a random number between min and max inclusive.'''
# Hint: random library
return 0
return randrange(min - 1, max)


def get_today():
'''Returns today's date in the format <month> <day>, <year> where month is a string, day & year are numbers.'''
# Note: Code must work regardless of today's date
# Example: November 19, 2021
# Hint: datetime library
return "November 19, 2021"
today = date.today()
return today.strftime("%B %d, %Y")


def get_stat(nums, type):
'''Returns <type> of an unsorted list <nums>, where type can be mean, median, mode.'''
# Example: get_stat([0, 1, 2], "median"), returns 1
# Hint: statistics library
return 0
if type == "mean":
return stats.mean(nums)
elif type == "median":
return stats.median(nums)
return stats.mode(nums)


def print_by_profit():
'''Print data/sales_records.csv in order sorted by profit.'''
# Hint: csv library
# Hint: use built-in sort() after parsing csv
# Hint: figure out how to print out each row in csv first
print("Working with csvs!")
with open('data/sales_records.csv') as file:
# Gets all rows in csv file and put into 2d array
data_rows = list(csv.reader(file, delimiter=','))
# Delete first row because it's just the column titles
print(data_rows.pop(0))
# Sort by profit (last index of each row)
data_rows.sort(key=lambda i:float(i[13]))
# Print each row
for row in data_rows:
print(row)


def main():
Expand Down
Empty file modified solution.py
100644 → 100755
Empty file.
Empty file modified solution2.py
100644 → 100755
Empty file.