diff --git a/Day2/.DS_Store b/Day2/.DS_Store new file mode 100644 index 00000000..5008ddfc Binary files /dev/null and b/Day2/.DS_Store differ diff --git a/Day2/intro-flask/.DS_Store b/Day2/intro-flask/.DS_Store new file mode 100644 index 00000000..0ed7ce6c Binary files /dev/null and b/Day2/intro-flask/.DS_Store differ diff --git a/Day2/intro-flask/data/listings.db b/Day2/intro-flask/data/listings.db new file mode 100644 index 00000000..46198ab3 Binary files /dev/null and b/Day2/intro-flask/data/listings.db differ diff --git a/Day2/intro-flask/models/listing.py b/Day2/intro-flask/models/listing.py new file mode 100644 index 00000000..af1fa310 --- /dev/null +++ b/Day2/intro-flask/models/listing.py @@ -0,0 +1,56 @@ +import sqlite3 + +class Listing: + + tablename = "listings" + dbpath = "..data/listings.db" + + def __init__(self, name, quantity, price, location, pk=None): + self.pk = pk + self.name = name + self.quantity = quantity + self.price = price + self.location = location + + + def insert(self): + with sqlite3.connect(self.dbpath) as conn: + cursor = conn.cursor() + cursor.execute("INSERT INTO listing VALUES(name, quantity, price, location)") + + + def update(self): + with sqlite3.connect(self.dbpath) as conn: + cursor = conn.cursor() + cursor.execute("""UPDATE listing SET name = self.name WHERE pk = self.pk""") + + + def delete(self): + pass + + + @classmethod + def select_all(cls): + with sqlite3.connect(cls.dbpath) as conn: + cursor = conn.cursor() + # TODO: prevent sql injection + sql = f"""SELECT * from {cls.tablename}""" + cursor.execute(sql) + return cursor.fetchall() + + + @classmethod + def select_one(cls): + with sqlite3.connect(cls.dbpath) as conn: + cursor = conn.cursor() + # TODO: prevent sql injection + sql = f"""SELECT * from {cls.tablename}""" + cursor.execute(sql) + return cursor.fetchone() + + +if __name__ == "__main__": + listings = Listing.select_all() + print(listings) + new_item = Listing("name", 5, 12.99, "test location") + new_item.insert() \ No newline at end of file diff --git a/Day2/run.py b/Day2/run.py new file mode 100644 index 00000000..03ca92f2 --- /dev/null +++ b/Day2/run.py @@ -0,0 +1,7 @@ +import os +from models.listing import Listing + +PATH = os.path.dirname(__file__) +Listing.dbpath = os.path.join(PATH, "data", "listings.db") + +print(Listing.select_all()) diff --git a/introduction_and_environment/data_types_and_control_flow/1_compare_check/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_compare_check/Solution/solution.py deleted file mode 100644 index ade03179..00000000 --- a/introduction_and_environment/data_types_and_control_flow/1_compare_check/Solution/solution.py +++ /dev/null @@ -1 +0,0 @@ -# Code your solution here diff --git a/introduction_and_environment/git/creating_a_repository/solution/solution.py b/introduction_and_environment/git/creating_a_repository/solution/solution.py index 3f6cd7a5..0d25a160 100644 --- a/introduction_and_environment/git/creating_a_repository/solution/solution.py +++ b/introduction_and_environment/git/creating_a_repository/solution/solution.py @@ -1,2 +1,2 @@ # Code your solution here - +answer = 'a' \ No newline at end of file diff --git a/introduction_and_environment/git/remote_repository/solution/solution.py b/introduction_and_environment/git/remote_repository/solution/solution.py index 3f6cd7a5..482a5499 100644 --- a/introduction_and_environment/git/remote_repository/solution/solution.py +++ b/introduction_and_environment/git/remote_repository/solution/solution.py @@ -1,2 +1,2 @@ # Code your solution here - +answer = 'd' diff --git a/introduction_and_environment/git/staging_area/solution/solution.py b/introduction_and_environment/git/staging_area/solution/solution.py index 3f6cd7a5..b8eb8f57 100644 --- a/introduction_and_environment/git/staging_area/solution/solution.py +++ b/introduction_and_environment/git/staging_area/solution/solution.py @@ -1,2 +1,2 @@ # Code your solution here - +answer = 'c' diff --git a/introduction_and_environment/git/update_code/solution/solution.py b/introduction_and_environment/git/update_code/solution/solution.py index f8c333fa..37b0a8ca 100644 --- a/introduction_and_environment/git/update_code/solution/solution.py +++ b/introduction_and_environment/git/update_code/solution/solution.py @@ -1 +1,2 @@ -# Code your solution here \ No newline at end of file +# Code your solution here +answer = 'b' \ No newline at end of file diff --git a/introduction_and_environment/unix_and_bash/basic_commands/solution/solution.py b/introduction_and_environment/unix_and_bash/basic_commands/solution/solution.py index efee9b73..c6c6d683 100644 --- a/introduction_and_environment/unix_and_bash/basic_commands/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/basic_commands/solution/solution.py @@ -2,9 +2,10 @@ ONE = 'man' # Assign the correct strings below -TWO = -THREE = -FOUR = -FIVE = -SIX = -SEVEN = +TWO = 'ls' +THREE = 'mkdir' +FOUR = 'touch' +FIVE = 'cp' +SIX = 'mv' +SEVEN = 'rm' + diff --git a/introduction_and_environment/unix_and_bash/commands_with_options/solution/solution.py b/introduction_and_environment/unix_and_bash/commands_with_options/solution/solution.py index f7e60d14..5109eeca 100644 --- a/introduction_and_environment/unix_and_bash/commands_with_options/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/commands_with_options/solution/solution.py @@ -1,9 +1,9 @@ # Assign the correct strings below -ONE = -TWO = -THREE = -FOUR = -FIVE = -SIX = -SEVEN = +ONE = 'cd exercises' +TWO = 'pwd' +THREE = 'cat textfile.txt' +FOUR = 'tail textfile.txt' +FIVE = 'ls -a' +SIX = 'head textfile.txt' +SEVEN = 'cp stackdata.json stockdata.json' diff --git a/introduction_and_environment/unix_and_bash/commands_with_options_2/solution/solution.py b/introduction_and_environment/unix_and_bash/commands_with_options_2/solution/solution.py index 8f4c1217..8ec23b4d 100644 --- a/introduction_and_environment/unix_and_bash/commands_with_options_2/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/commands_with_options_2/solution/solution.py @@ -1,8 +1,8 @@ # Assign the correct strings below -ONE = -TWO = -THREE = -FOUR = -FIVE = -SIX = +ONE = 'grep elephant book.txt' +TWO = 'mv notes.txt newdir' +THREE = 'grep -r string testdir' +FOUR = 'rm -d empty' +FIVE = 'cd' +SIX = 'rm -r Downloads' diff --git a/introduction_and_environment/unix_and_bash/intermediate_commands/solution/solution.py b/introduction_and_environment/unix_and_bash/intermediate_commands/solution/solution.py index 1b20d256..30e1f6f9 100644 --- a/introduction_and_environment/unix_and_bash/intermediate_commands/solution/solution.py +++ b/introduction_and_environment/unix_and_bash/intermediate_commands/solution/solution.py @@ -1,7 +1,7 @@ # Assign the correct strings below -ONE = -TWO = -THREE = -FOUR = -FIVE = +ONE = 'mkdir testdir && cd testdir' +TWO = 'cat textfile.txt | grep and' +THREE = 'ls >> contents.txt' +FOUR = 'cd current || mkdir current' +FIVE = 'pwd > current_path.txt' diff --git a/introduction_to_python/class_protocols/1_a_vector_class_constructor/solution/solution.py b/introduction_to_python/class_protocols/1_a_vector_class_constructor/solution/solution.py index e69de29b..5f6c8267 100644 --- a/introduction_to_python/class_protocols/1_a_vector_class_constructor/solution/solution.py +++ b/introduction_to_python/class_protocols/1_a_vector_class_constructor/solution/solution.py @@ -0,0 +1,9 @@ +class Vector3D: + + def __init__(self, x=0, y=0, z=0): + self.x = x + self.y = y + self.z = z + + +vector1 = Vector3D(1, 2, 3) diff --git a/introduction_to_python/class_protocols/1_b_print_vector/solution/solution.py b/introduction_to_python/class_protocols/1_b_print_vector/solution/solution.py index e69de29b..d599d260 100644 --- a/introduction_to_python/class_protocols/1_b_print_vector/solution/solution.py +++ b/introduction_to_python/class_protocols/1_b_print_vector/solution/solution.py @@ -0,0 +1,13 @@ +class Vector3D: + + def __init__(self, x=0, y=0, z=0): + self.x = x + self.y = y + self.z = z + + def __str__(self): + return f'x = {self.x}, y = {self.y}, z = {self.z}' + + +vector1 = Vector3D(3, 4, 2) +print(vector1) diff --git a/introduction_to_python/class_protocols/2_a_add_vectors/solution/solution.py b/introduction_to_python/class_protocols/2_a_add_vectors/solution/solution.py index e69de29b..833e094b 100644 --- a/introduction_to_python/class_protocols/2_a_add_vectors/solution/solution.py +++ b/introduction_to_python/class_protocols/2_a_add_vectors/solution/solution.py @@ -0,0 +1,12 @@ +class Vector3D: + + def __init__(self, x=0, y=0, z=0): + self.x = x + self.y = y + self.z = z + + def __add__(self, other): + x = self.x + other.x + y = self.y + other.y + z = self.z + other.z + return Vector3D(x, y, z) diff --git a/introduction_to_python/class_protocols/2_a_comparison_lt_gt/solution/solution.py b/introduction_to_python/class_protocols/2_a_comparison_lt_gt/solution/solution.py index e69de29b..76b85155 100644 --- a/introduction_to_python/class_protocols/2_a_comparison_lt_gt/solution/solution.py +++ b/introduction_to_python/class_protocols/2_a_comparison_lt_gt/solution/solution.py @@ -0,0 +1,31 @@ +import math + + +class Vector3D: + def __init__(self, x=0, y=0, z=0): + self.x = x + self.y = y + self.z = z + + def __it__(self, other): + if self.x < other.x: + return math.sqrt(x) + elif self.y < other.y: + return True + else: + self.z < other.z + return True + + def __gt__(self, other): + if self.x > other.x: + return True + elif self.y > other.y: + return True + else: + self.z > other.z + return True + + +print(vec1=math.sqrt((1, 5, 3))) +print(vec2=math.sqrt((4, 4, 1))) +print(vec3=math.sqrt((1, 5, 2))) diff --git a/introduction_to_python/classes/1_a_employee_class/solution/solution.py b/introduction_to_python/classes/1_a_employee_class/solution/solution.py index e69de29b..8500ad83 100644 --- a/introduction_to_python/classes/1_a_employee_class/solution/solution.py +++ b/introduction_to_python/classes/1_a_employee_class/solution/solution.py @@ -0,0 +1,10 @@ +class Employee: + + def __init__(self, name, employee_id, salary, years_at_company): + self.name = name + self.employee_id = employee_id + self.salary = salary + self.years_at_company = years_at_company + + +cosette = Employee("Cosette Rodger", 1, 100000, 4) diff --git a/introduction_to_python/classes/1_b_employee_raise/solution/solution.py b/introduction_to_python/classes/1_b_employee_raise/solution/solution.py index e69de29b..bdb221b7 100644 --- a/introduction_to_python/classes/1_b_employee_raise/solution/solution.py +++ b/introduction_to_python/classes/1_b_employee_raise/solution/solution.py @@ -0,0 +1,18 @@ +class Employee: + + def __init__(self, name, employee_id, salary, years_at_company): + self.name = name + self.employee_id = employee_id + self.salary = salary + self.years_at_company = years_at_company + + +def give_raises(employee_lst): + for emp in employee_lst: + if emp.years_at_company <= 5: + emp.salary = emp.salary + 5000 + elif emp.years_at_company > 5 and emp.years_at_company < 10: + emp.salary = emp.salary + 8000 + else: + emp.years_at_company >= 10 + emp.salary = emp.salary + 10000 diff --git a/introduction_to_python/classes/1_c_employee_sort/solution/solution.py b/introduction_to_python/classes/1_c_employee_sort/solution/solution.py index e69de29b..041c3949 100644 --- a/introduction_to_python/classes/1_c_employee_sort/solution/solution.py +++ b/introduction_to_python/classes/1_c_employee_sort/solution/solution.py @@ -0,0 +1,14 @@ +class Employee: + + def __init__(self, name, employee_id, salary, years_at_company): + self.name = name + self.employee_id = employee_id + self.salary = salary + self.years_at_company = years_at_company + + +def sort_employees(employee_list): + names = [] + for employee in employee_list: + names.append(employee.name) + return sorted(names) diff --git a/introduction_to_python/classes/2_a_person_child/solution/solution.py b/introduction_to_python/classes/2_a_person_child/solution/solution.py index e69de29b..5756f1ee 100644 --- a/introduction_to_python/classes/2_a_person_child/solution/solution.py +++ b/introduction_to_python/classes/2_a_person_child/solution/solution.py @@ -0,0 +1,25 @@ +class Person: + + def __init__(self, name, age, spouse, children): + self.name = name + self.age = age + self.spouse = spouse + self.children = children + + +class Child(Person): + def __init__(self, name, age, spouse, children, parents): + Person.__init__(self, name, age, spouse, children) + self.parents = parents + + +jim = Person('Jim Brown', 45, None, []) +suzy = Person('Suzy Brown', 42, None, []) +martha = Child('Martha Brown', 18, None, [], []) + +jim.spouse = suzy +suzy.spouse = jim +jim.children.append(martha) +suzy.children.append(martha) +martha.parents.append(jim) +martha.parents.append(suzy) diff --git a/introduction_to_python/classes/2_b_person_get_sibilings/solution/solution.py b/introduction_to_python/classes/2_b_person_get_sibilings/solution/solution.py index e69de29b..ce3fe1fc 100644 --- a/introduction_to_python/classes/2_b_person_get_sibilings/solution/solution.py +++ b/introduction_to_python/classes/2_b_person_get_sibilings/solution/solution.py @@ -0,0 +1,20 @@ +class Person: + + def __init__(self, name, age, spouse, children): + self.name = name + self.age = age + self.spouse = spouse + self.children = children + + +class Child(Person): + + def __init__(self, name, age, spouse, children, parents): + Person.__init__(self, name, age, spouse, children) + self.parents = parents + + def get_siblings(self, children): + self.child_by_age = [] + children.sort(key=self.child_by_age) + for self.child in children: + return self.children.age diff --git a/introduction_to_python/functions/1_below_100/solution/solution.py b/introduction_to_python/functions/1_below_100/solution/solution.py index aeb50baa..73d0b751 100644 --- a/introduction_to_python/functions/1_below_100/solution/solution.py +++ b/introduction_to_python/functions/1_below_100/solution/solution.py @@ -1 +1,11 @@ # Write your solution here + +num = int() +def below_100(num): + if num < 100: + return("less than 100") + else: + return("greater than 100") + +below_100(50) +below_100(200) diff --git a/introduction_to_python/functions/1_concat_args/solution/solution.py b/introduction_to_python/functions/1_concat_args/solution/solution.py index e69de29b..531c39ba 100644 --- a/introduction_to_python/functions/1_concat_args/solution/solution.py +++ b/introduction_to_python/functions/1_concat_args/solution/solution.py @@ -0,0 +1,4 @@ +def concat_input(val_1, val_2): + return val_1 + val_2 + +concat_input(val_1 = "hello", val_2 = "world") diff --git a/introduction_to_python/functions/1_return_hello/solution/solution.py b/introduction_to_python/functions/1_return_hello/solution/solution.py index e69de29b..bd33b9a6 100644 --- a/introduction_to_python/functions/1_return_hello/solution/solution.py +++ b/introduction_to_python/functions/1_return_hello/solution/solution.py @@ -0,0 +1,4 @@ +def hello(name): + return("Hello " + name) + +hello("Dorothy") diff --git a/introduction_to_python/functions/2_max_value/solution/solution.py b/introduction_to_python/functions/2_max_value/solution/solution.py index aeb50baa..a3e9b179 100644 --- a/introduction_to_python/functions/2_max_value/solution/solution.py +++ b/introduction_to_python/functions/2_max_value/solution/solution.py @@ -1 +1,6 @@ # Write your solution here + +def max_val(a, b, c): + return max(a, b, c) + +print(max_val(1, 4, 2)) diff --git a/introduction_to_python/functions/2_shut_down/solution/solution.py b/introduction_to_python/functions/2_shut_down/solution/solution.py index e69de29b..10659820 100644 --- a/introduction_to_python/functions/2_shut_down/solution/solution.py +++ b/introduction_to_python/functions/2_shut_down/solution/solution.py @@ -0,0 +1,7 @@ +def shut_down(x): + if x == True: + return "SHUTDOWN" + else: + return "SHUTDOWN ABORTED" + +#print(shut_down(x=0)) diff --git a/introduction_to_python/functions/2_variable_arguments/solution/solution.py b/introduction_to_python/functions/2_variable_arguments/solution/solution.py index e69de29b..94fc36d3 100644 --- a/introduction_to_python/functions/2_variable_arguments/solution/solution.py +++ b/introduction_to_python/functions/2_variable_arguments/solution/solution.py @@ -0,0 +1,4 @@ +def concat_args(*args): + return "" + "" + +print(concat_args("Hello ", "There")) diff --git a/introduction_to_python/functions/3_count_even/solution/solution.py b/introduction_to_python/functions/3_count_even/solution/solution.py index e69de29b..46b10552 100644 --- a/introduction_to_python/functions/3_count_even/solution/solution.py +++ b/introduction_to_python/functions/3_count_even/solution/solution.py @@ -0,0 +1,6 @@ +def count_even(*args): + for num in args: + if num % 2 == 0: + return num + +count_even(1, 2, 3, 4) == 2 diff --git a/introduction_to_python/functions/3_divisible_by_3/solution/solution.py b/introduction_to_python/functions/3_divisible_by_3/solution/solution.py index fabb9be6..f6044fe0 100644 --- a/introduction_to_python/functions/3_divisible_by_3/solution/solution.py +++ b/introduction_to_python/functions/3_divisible_by_3/solution/solution.py @@ -1 +1,9 @@ # Write your code here + +def divisible_by_3(*args): + div_3 = [] + for num in args: + if num % 3 == 0: + return div_3.append(num) + +print(divisible_by_3(2,3,5,6,9))