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
28 changes: 23 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,55 @@
from math import sqrt


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
total = 0
for i in range(b):
total = sum(total,a)
return total


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


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
square = 1
total = 1
while total < num:
square += 1
total = square*square
return square


def main():
Expand Down
29 changes: 27 additions & 2 deletions main2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,40 @@ 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 []
list = []
for i in range(len(nums)):
if nums[i] % 2 == 0:
list.append(1)
else:
list.append(0)

return list


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
temp = 1
mode = 1
first = nums[0]
second = first
i = 1
for i in range(len(nums)):
if first == nums[i]:
temp += 1
if temp > mode:
mode = temp
second = first
else:
if temp > mode:
mode = temp
second = first
temp = 1
first = nums[i]

return second


def main():
Expand Down
36 changes: 30 additions & 6 deletions main3.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,63 @@
#### INCLUDE ANY IMPORTS YOU NEED HERE, DO NOT PIP INSTALL ANY LIBRARIES ####

from math import sqrt, floor
import random
import datetime
from statistics import mean, median, mode
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
total = sqrt(num)
if floor(total) * floor(total) == num:
return total
else:
return -1


def random_num_generator(min, max):
'''Returns a random number between min and max inclusive.'''
# Hint: random library
return 0
randomNum = random.randint(min, max)
return randomNum


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"
current = datetime.datetime.now().strftime("%F")
month = {1: "January", 2: "February", 3: "March", 4: "April",
5: "May", 6: "June", 7: "July", 8: "August",
9: "September", 10: "October", 11: "November", 12: "December",}
today = current.split('-')

return month[int(today[1])] + " " + today[2] + ", " + today[0]


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 mean(nums)
elif type == "median":
return median(nums)
else:
return 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:
row = list(csv.reader(file, delimiter = ","))
row.sort()
for i in row:
print(i)


def main():
Expand Down