diff --git a/1.py b/1.py index fd6cfeb..3847ed9 100644 --- a/1.py +++ b/1.py @@ -29,4 +29,74 @@ 'water': 300, 'milk': 300, 'money': 0, -} \ No newline at end of file +} + + +class Coffee_Machine: + def __init__(self): + self.money = 0 + self.inventory = INVENTORY + self.menu = MENU + self.is_on = True + + def report(self): + print(f"Water: {self.inventory['water']}ml") + print(f"Milk: {self.inventory['milk']}ml") + print(f"Coffee: {self.inventory['coffee']}g") + print(f"Money: ${self.money}") + + def check_resources(self, drink): + for item in self.menu[drink]['ingredients']: + if self.inventory[item] < self.menu[drink]['ingredients'][item]: + print(f"Sorry there is not enough {item}.") + return False + return True + + def clean_input_money(input_): + if input_.isdigit() == False: + return 0 + else: + return input_ + + def process_coins(self): + print("Please insert coins.") + total = 0 + total += int(Coffee_Machine.clean_input_money(input("How many quarters?: "))) * 0.25 + total += int(Coffee_Machine.clean_input_money(input("How many dimes?: "))) * 0.1 + total += int(Coffee_Machine.clean_input_money(input("How many nickles?: "))) * 0.05 + total += int(Coffee_Machine.clean_input_money(input("How many pennies?: "))) * 0.01 + return total + + def make_coffee(self, drink): + for item in self.menu[drink]['ingredients']: + self.inventory[item] -= self.menu[drink]['ingredients'][item] + self.money += self.menu[drink]['price'] + print(f"Here is your {drink}. Enjoy!") + + def turn_off(self): + self.is_on = False + + +def __main__(): + coffee_machine = Coffee_Machine() + while coffee_machine.is_on: + choice = input("What would you like? (espresso/latte/flat white): ").lower() + if choice != 'espresso' and choice != 'latte' and choice != 'flat white' and choice != 'off' and choice != 'report': + print('your choise is not valid, please try again') + __main__() + if choice == 'off': + coffee_machine.turn_off() + elif choice == 'report': + coffee_machine.report() + else: + if coffee_machine.check_resources(choice): + payment = coffee_machine.process_coins() + if payment < coffee_machine.menu[choice]['price']: + print("Sorry that's not enough money. Money refunded.") + else: + change = round(payment - coffee_machine.menu[choice]['price'], 2) + print(f"Here is ${change} in change.") + coffee_machine.make_coffee(choice) + + +__main__() \ No newline at end of file diff --git a/2.py b/2.py index bc686dd..3157f54 100644 --- a/2.py +++ b/2.py @@ -2,7 +2,7 @@ def send_sms(msg, phone): - """Sends a given message to a given phone via SMS. + """Sends a given message to a given phone number as SMS. You don't have to implement this function. """ @@ -16,18 +16,40 @@ def send_email(msg, email): """ ... -# Solution goes here +class Patient(object): + def __init__(self, first_name, last_name, title, date, email, phone, mobile_phone): + self.first_name = first_name + self.last_name = last_name + self.title = title + self.age = datetime.now() - date + self.email = email + self.phone = phone + self.mobile_phone = mobile_phone + + def greeting(self): + return f"Hello, {self.title} {self.last_name}!" + + def send_sms(self, msg): + send_sms(msg, self.mobile_phone) + + def send_email(self, msg): + send_email(msg, self.email) + + def send_appointment_reminder(self, time): + send_sms(f"Hi {self.first_name}, you have an appointment tomorrow at {time}.", self.mobile_phone) + send_email(f"Hi {self.first_name}, you have an appointment tomorrow at {time}.", self.email) patient1 = Patient( - 'John', - 'Doe', - 'mr.', + "John", + "Doe", + "mr.", datetime(1990, 2, 28), - 'john.doe@gmail.com', - '+3345451555', - '+6693932030', + "john.doe@gmail.com", + "+3345451555", + "+6693932030", ) + print(patient1.greeting()) patient1.send_appointment_reminder(datetime(2023, 10, 13, 13, 0)) diff --git a/oop-coffee-machine-start.zip b/oop-coffee-machine-start.zip new file mode 100644 index 0000000..aaaf8fa Binary files /dev/null and b/oop-coffee-machine-start.zip differ diff --git a/oop-coffee-machine-start/oop-coffee-machine-start/coffee_maker.py b/oop-coffee-machine-start/oop-coffee-machine-start/coffee_maker.py new file mode 100644 index 0000000..fad03d9 --- /dev/null +++ b/oop-coffee-machine-start/oop-coffee-machine-start/coffee_maker.py @@ -0,0 +1,29 @@ +class CoffeeMaker: + """Models the machine that makes the coffee""" + def __init__(self): + self.resources = { + "water": 300, + "milk": 200, + "coffee": 100, + } + + def report(self): + """Prints a report of all resources.""" + print(f"Water: {self.resources['water']}ml") + print(f"Milk: {self.resources['milk']}ml") + print(f"Coffee: {self.resources['coffee']}g") + + def is_resource_sufficient(self, drink): + """Returns True when order can be made, False if ingredients are insufficient.""" + can_make = True + for item in drink.ingredients: + if drink.ingredients[item] > self.resources[item]: + print(f"Sorry there is not enough {item}.") + can_make = False + return can_make + + def make_coffee(self, order): + """Deducts the required ingredients from the resources.""" + for item in order.ingredients: + self.resources[item] -= order.ingredients[item] + print(f"Here is your {order.name} ☕️. Enjoy!") diff --git a/oop-coffee-machine-start/oop-coffee-machine-start/main.py b/oop-coffee-machine-start/oop-coffee-machine-start/main.py new file mode 100644 index 0000000..f0810d6 --- /dev/null +++ b/oop-coffee-machine-start/oop-coffee-machine-start/main.py @@ -0,0 +1,29 @@ +from menu import Menu, MenuItem +from coffee_maker import CoffeeMaker +from money_machine import MoneyMachine + + +def __main__(): + coffee_maker = CoffeeMaker() + menu = Menu() + money_machine = MoneyMachine() + is_on = True + + while is_on: + options = menu.get_items() + choice = input(f"What would you like? ({options}): ") + if choice == "off": + is_on = False + elif choice == "report": + coffee_maker.report() + money_machine.report() + else: + drink = menu.find_drink(choice) + if coffee_maker.is_resource_sufficient( + drink + ) and money_machine.make_payment(drink.cost): + coffee_maker.make_coffee(drink) + + +if __name__ == "__main__": + __main__() diff --git a/oop-coffee-machine-start/oop-coffee-machine-start/menu.py b/oop-coffee-machine-start/oop-coffee-machine-start/menu.py new file mode 100644 index 0000000..549d5b4 --- /dev/null +++ b/oop-coffee-machine-start/oop-coffee-machine-start/menu.py @@ -0,0 +1,34 @@ +class MenuItem: + """Models each Menu Item.""" + def __init__(self, name, water, milk, coffee, cost): + self.name = name + self.cost = cost + self.ingredients = { + "water": water, + "milk": milk, + "coffee": coffee + } + + +class Menu: + """Models the Menu with drinks.""" + def __init__(self): + self.menu = [ + MenuItem(name="latte", water=200, milk=150, coffee=24, cost=2.5), + MenuItem(name="espresso", water=50, milk=0, coffee=18, cost=1.5), + MenuItem(name="cappuccino", water=250, milk=50, coffee=24, cost=3), + ] + + def get_items(self): + """Returns all the names of the available menu items""" + options = "" + for item in self.menu: + options += f"{item.name}/" + return options + + def find_drink(self, order_name): + """Searches the menu for a particular drink by name. Returns that item if it exists, otherwise returns None""" + for item in self.menu: + if item.name == order_name: + return item + print("Sorry that item is not available.") diff --git a/oop-coffee-machine-start/oop-coffee-machine-start/money_machine.py b/oop-coffee-machine-start/oop-coffee-machine-start/money_machine.py new file mode 100644 index 0000000..09ca70a --- /dev/null +++ b/oop-coffee-machine-start/oop-coffee-machine-start/money_machine.py @@ -0,0 +1,39 @@ +class MoneyMachine: + + CURRENCY = "$" + + COIN_VALUES = { + "quarters": 0.25, + "dimes": 0.10, + "nickles": 0.05, + "pennies": 0.01 + } + + def __init__(self): + self.profit = 0 + self.money_received = 0 + + def report(self): + """Prints the current profit""" + print(f"Money: {self.CURRENCY}{self.profit}") + + def process_coins(self): + """Returns the total calculated from coins inserted.""" + print("Please insert coins.") + for coin in self.COIN_VALUES: + self.money_received += int(input(f"How many {coin}?: ")) * self.COIN_VALUES[coin] + return self.money_received + + def make_payment(self, cost): + """Returns True when payment is accepted, or False if insufficient.""" + self.process_coins() + if self.money_received >= cost: + change = round(self.money_received - cost, 2) + print(f"Here is {self.CURRENCY}{change} in change.") + self.profit += cost + self.money_received = 0 + return True + else: + print("Sorry that's not enough money. Money refunded.") + self.money_received = 0 + return False diff --git a/quiz-game-start.zip b/quiz-game-start.zip new file mode 100644 index 0000000..f546395 Binary files /dev/null and b/quiz-game-start.zip differ diff --git a/quiz-game-start/data.py b/quiz-game-start/data.py new file mode 100644 index 0000000..b5b46ec --- /dev/null +++ b/quiz-game-start/data.py @@ -0,0 +1,14 @@ +question_data = [ +{"text": "A slug's blood is green.", "answer": "True"}, +{"text": "The loudest animal is the African Elephant.", "answer": "False"}, +{"text": "Approximately one quarter of human bones are in the feet.", "answer": "True"}, +{"text": "The total surface area of a human lungs is the size of a football pitch.", "answer": "True"}, +{"text": "In West Virginia, USA, if you accidentally hit an animal with your car, you are free to take it home to eat.", "answer": "True"}, +{"text": "In London, UK, if you happen to die in the House of Parliament, you are entitled to a state funeral.", "answer": "False"}, +{"text": "It is illegal to pee in the Ocean in Portugal.", "answer": "True"}, +{"text": "You can lead a cow down stairs but not up stairs.", "answer": "False"}, +{"text": "Google was originally called 'Backrub'.", "answer": "True"}, +{"text": "Buzz Aldrin's mother's maiden name was 'Moon'.", "answer": "True"}, +{"text": "No piece of square dry paper can be folded in half more than 7 times.", "answer": "False"}, +{"text": "A few ounces of chocolate can to kill a small dog.", "answer": "True"} +] \ No newline at end of file diff --git a/quiz-game-start/main.py b/quiz-game-start/main.py new file mode 100644 index 0000000..c441008 --- /dev/null +++ b/quiz-game-start/main.py @@ -0,0 +1,18 @@ +import question_model +import quiz_brain +import data + +question_bank = [] + +for question in data.question_data: + question_text = question["text"] + question_answer = question["answer"] + new_question = question_model.Question(question_text, question_answer) + question_bank.append(new_question) + +quiz = quiz_brain.QuizBrain(question_bank) + +while quiz.still_has_questions(): + quiz.next_question() + +print("You've completed the quiz") \ No newline at end of file diff --git a/quiz-game-start/question_model.py b/quiz-game-start/question_model.py new file mode 100644 index 0000000..bc103a2 --- /dev/null +++ b/quiz-game-start/question_model.py @@ -0,0 +1,4 @@ +class Question: + def __init__(self, q_text, q_answer): + self.text = q_text + self.answer = q_answer diff --git a/quiz-game-start/quiz_brain.py b/quiz-game-start/quiz_brain.py new file mode 100644 index 0000000..955ea29 --- /dev/null +++ b/quiz-game-start/quiz_brain.py @@ -0,0 +1,36 @@ +class QuizBrain: + def __init__(self, q_list): + self.question_number = 0 + self.question_list = q_list + self.score = 0 + + def next_question(self): + current_question = self.question_list[self.question_number] + self.question_number += 1 + user_answer = input(f"Q.{self.question_number}: {current_question.text} (True/False)?: ") + self.check_answer(user_answer, current_question.answer) + + def still_has_questions(self): + return self.question_number < len(self.question_list) + + def check_answer(self, user_answer, correct_answer): + if user_answer.lower() == correct_answer.lower(): + print("You got it right!") + else: + print("That's wrong.") + print(f"The correct answer was: {correct_answer}.") + print(f"Your current score is: {self.score}/{self.question_number}") + print("\n") + + def start(self): + while self.still_has_questions(): + self.next_question() + print("You've completed the quiz.") + print(f"Your final score was: {self.score}/{self.question_number}") + print("\n") + + + + + + diff --git a/turt/Spirograph.py b/turt/Spirograph.py new file mode 100644 index 0000000..3e87e4a --- /dev/null +++ b/turt/Spirograph.py @@ -0,0 +1,16 @@ +import turtle as t +import random + +t.colormode(255) +tim = t.Turtle() +tim.speed("fastest") +tim.shape("turtle") + +for _ in range(72): + tim.color((random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))) + tim.circle(100) + tim.left(5) + +screen = t.Screen() +screen.exitonclick() + diff --git a/turt/dottedline.py b/turt/dottedline.py new file mode 100644 index 0000000..c3d9409 --- /dev/null +++ b/turt/dottedline.py @@ -0,0 +1,13 @@ +import turtle + +def dottedline(t, length): + for i in range(4): + t.fd(length) + t.up() + t.fd(length) + t.down() + +bob = turtle.Turtle() +dottedline(bob, 100) +turtle.mainloop() + diff --git a/turt/randomwalk.py b/turt/randomwalk.py new file mode 100644 index 0000000..04cea0c --- /dev/null +++ b/turt/randomwalk.py @@ -0,0 +1,19 @@ +import turtle as t +import random + +t.colormode(255) +tim = t.Turtle() +tim.speed("fastest") +tim.shape("turtle") +colors = ["CornflowerBlue", "DarkOrchid", "IndianRed", "DeepSkyBlue", "LightSeaGreen", "wheat", "SlateGray", "SeaGreen"] +directions = [0, 90, 180, 270] + + +for _ in range(200): + tim.pensize(random.randint(1, 10)) + tim.color(random.choice(colors)) + tim.forward(30) + tim.setheading(random.choice(directions)) + +screen = t.Screen() +screen.exitonclick() \ No newline at end of file diff --git a/turt/squre.py b/turt/squre.py new file mode 100644 index 0000000..4863ab6 --- /dev/null +++ b/turt/squre.py @@ -0,0 +1,10 @@ +import turtle + +def square(t, length): + for i in range(4): + t.fd(length) + t.lt(90) + +bob = turtle.Turtle() +square(bob, 100) +turtle.mainloop() \ No newline at end of file diff --git a/turt/triangles.py b/turt/triangles.py new file mode 100644 index 0000000..5a6225a --- /dev/null +++ b/turt/triangles.py @@ -0,0 +1,29 @@ +import turtle + +def polygon(t, n, length): + angle = 360 / n + for i in range(n): + t.fd(length) + t.lt(angle) + +def nangle(t, n, length): + for i in range(n): + polygon(t, n, length) + t.lt(360 / n) + +def change_color_each_pulygon(t, n, length): + for i in range(n): + t.color("red") + polygon(t, n, length) + t.color("blue") + t.lt(360 / n) + +def main(): + bob = turtle.Turtle() + bob.speed(0) + bob.hideturtle() + change_color_each_pulygon(bob, 10, 50) + turtle.mainloop() + +if __name__ == "__main__": + main() \ No newline at end of file