From b7342af474adb1586d5c82b57b5a84b212ba29f8 Mon Sep 17 00:00:00 2001 From: storm Date: Mon, 2 Oct 2023 10:21:40 +0700 Subject: [PATCH 1/5] caufey mashiin --- 1.py | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2.py | 5 +++++ 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/1.py b/1.py index fd6cfeb..ba8a011 100644 --- a/1.py +++ b/1.py @@ -29,4 +29,75 @@ 'water': 300, 'milk': 300, 'money': 0, -} \ No newline at end of file +} + +while True: + input_coffee = input("What would you like? (espresso/latte/flat white): ").lower() + + if input_coffee == 'off': + exit() + elif input_coffee == 'report': + print(f"Water: {INVENTORY['water']}ml") + print(f"Milk: {INVENTORY['milk']}ml") + print(f"Coffee: {INVENTORY['coffee']}g") + print(f"Money: ${INVENTORY['money']}") + + coffee = MENU.get(input_coffee) + if coffee: + not_enough_resource = False + for ingredient, quantity in coffee['ingredients'].items(): + if INVENTORY.get(ingredient, 0) < quantity: + print(f"Sorry there is not enough {ingredient}.") + not_enough_resource = True + break + + if not_enough_resource: + continue + + + cost = coffee['price'] + print(f"The price of the {input_coffee} is ${cost}") + print("Please insert coins!") + try: + quarters = int(input("How many quarters? ")) * 0.25 + except ValueError: + quarters = 0 + + try: + dimes = int(input("How many dimes? ")) * 0.10 + except ValueError: + dimes = 0 + + try: + nickels = int(input("How many nickels? ")) * 0.05 + except ValueError: + nickels = 0 + + try: + pennies = int(input("How many pennies? ")) * 0.01 + except ValueError: + pennies = 0 + + total_inserted = quarters + dimes + nickels + pennies + + + + if total_inserted < cost: + print("That's not enough money!") + print(f"{total_inserted}$ refunded.") + else: + change = total_inserted - cost + change = round(change, 2) + INVENTORY['money'] += cost + print(f"Here is your {input_coffee}. Enjoy!") + + for ingredient, quantity in coffee['ingredients'].items(): + INVENTORY[ingredient] -= quantity + + if change > 0: + print(f"Here is ${change}$ in change") + else: + print("Invalid selection; Please choose from either espresso, latte, or flat white") + + + diff --git a/2.py b/2.py index bc686dd..3bdbd9e 100644 --- a/2.py +++ b/2.py @@ -1,6 +1,11 @@ from datetime import datetime +class Patient: + + + + def send_sms(msg, phone): """Sends a given message to a given phone via SMS. From a20b6852f1b3ca1479f632e2c98c1f180132c926 Mon Sep 17 00:00:00 2001 From: storm Date: Mon, 2 Oct 2023 11:45:19 +0700 Subject: [PATCH 2/5] paixen hospital --- 2.py | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/2.py b/2.py index 3bdbd9e..dc0e93c 100644 --- a/2.py +++ b/2.py @@ -1,13 +1,46 @@ from datetime import datetime class Patient: - + def __init__(self, first_name, last_name, title, date_of_birth, email, phone, alt_phone): + + self.first_name = first_name + self.last_name = last_name + self.title = title + self.date_of_birth = date_of_birth + self.email = email + self.phone = phone + self.alt_phone = alt_phone + + def greeting(self): + + return f"\nHello {self.title} {self.first_name} {self.last_name}! \n" + + def calculate_age(self): + birthdate = self.date_of_birth + current_date = datetime.now() + age = current_date - birthdate + years = age.days // 365 + months = (age.days % 365) // 30 + days = (age.days % 365) % 30 + return f"{years} Years | {months} Months | {days} Days Old\n" + def send_appointment_reminder(self, appointment_date): + + message = f"Dear {self.first_name}, you have an appointment on {appointment_date}. \n" + + send_sms(message, self.phone) + send_email(message, self.email) + + + def send_sms(msg, phone): - """Sends a given message to a given phone via SMS. + print(f"Sending SMS to {phone}: {msg}") + + """Sends a given message to a given phone via SMS + . You don't have to implement this function. """ @@ -15,6 +48,7 @@ def send_sms(msg, phone): def send_email(msg, email): + print(f"Sending email to {email}: {msg}") """Sends a given message to a given address as email. You don't have to implement this function. @@ -35,4 +69,6 @@ def send_email(msg, email): print(patient1.greeting()) +print(patient1.calculate_age()) + patient1.send_appointment_reminder(datetime(2023, 10, 13, 13, 0)) From 4ce6e45f648cd6b98db387e89f1e79ca371d4ec9 Mon Sep 17 00:00:00 2001 From: storm Date: Tue, 3 Oct 2023 10:07:01 +0700 Subject: [PATCH 3/5] class caufey --- oop-coffee-machine-start/coffee_maker.py | 29 +++++++++++++++++ oop-coffee-machine-start/main.py | 28 ++++++++++++++++ oop-coffee-machine-start/menu.py | 34 ++++++++++++++++++++ oop-coffee-machine-start/money_machine.py | 39 +++++++++++++++++++++++ 4 files changed, 130 insertions(+) create mode 100644 oop-coffee-machine-start/coffee_maker.py create mode 100644 oop-coffee-machine-start/main.py create mode 100644 oop-coffee-machine-start/menu.py create mode 100644 oop-coffee-machine-start/money_machine.py diff --git a/oop-coffee-machine-start/coffee_maker.py b/oop-coffee-machine-start/coffee_maker.py new file mode 100644 index 0000000..fad03d9 --- /dev/null +++ b/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/main.py b/oop-coffee-machine-start/main.py new file mode 100644 index 0000000..2d2d663 --- /dev/null +++ b/oop-coffee-machine-start/main.py @@ -0,0 +1,28 @@ +from menu import Menu, MenuItem +from coffee_maker import CoffeeMaker +from money_machine import MoneyMachine + + +menu = Menu() +coffee_maker = CoffeeMaker() +money_machine = MoneyMachine() + + +is_on = True + +while is_on: + choice = input("What would you like? (espresso/latte/cappuccino): ") + if choice == 'off': + exit() + elif choice == 'report': + coffee_maker.report() + money_machine.report() + else: + drink = menu.find_drink(choice) + if drink: + if coffee_maker.is_resource_sufficient(drink): + if money_machine.make_payment(drink.cost): + coffee_maker.make_coffee(drink) + + + diff --git a/oop-coffee-machine-start/menu.py b/oop-coffee-machine-start/menu.py new file mode 100644 index 0000000..549d5b4 --- /dev/null +++ b/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/money_machine.py b/oop-coffee-machine-start/money_machine.py new file mode 100644 index 0000000..09ca70a --- /dev/null +++ b/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 From c16e0212be3c4e8fefd1086feac32193dc7ccb35 Mon Sep 17 00:00:00 2001 From: storm Date: Wed, 4 Oct 2023 11:03:01 +0700 Subject: [PATCH 4/5] api thing done --- quiz-game-start/cool_quiz.py | 47 +++++++++++++++++++++++++++++++ quiz-game-start/data.py | 14 +++++++++ quiz-game-start/main.py | 22 +++++++++++++++ quiz-game-start/question_model.py | 5 ++++ quiz-game-start/quiz_brain.py | 30 ++++++++++++++++++++ 5 files changed, 118 insertions(+) create mode 100644 quiz-game-start/cool_quiz.py create mode 100644 quiz-game-start/data.py create mode 100644 quiz-game-start/main.py create mode 100644 quiz-game-start/question_model.py create mode 100644 quiz-game-start/quiz_brain.py diff --git a/quiz-game-start/cool_quiz.py b/quiz-game-start/cool_quiz.py new file mode 100644 index 0000000..3a4907a --- /dev/null +++ b/quiz-game-start/cool_quiz.py @@ -0,0 +1,47 @@ +import requests +import html + + +url = "https://opentdb.com/api.php?amount=10&difficulty=easy&type=boolean" + +class CoolQuizBrain: + def __init__(self): + result = requests.get(url) + + self.question_data = result.json() + self.current_question_index = 0 + self.questions = self.question_data["results"] + self.category = self.questions[self.current_question_index]["category"] + self.question = self.questions[self.current_question_index]["question"] + self.answer = self.questions[self.current_question_index]["correct_answer"] + + self.question_number = 0 + self.question_correct = 0 + + def correctQuestion(self): + self.question_correct += 1 + + def nextQuestion(self): + self.question_number += 1 + + def answercheck(self): + + + for el in self.questions: + self.question = el["question"] + self.answer = el["correct_answer"] + + self.decoded_sentence = html.unescape(self.question) + + user_input = input(f"True or False: {self.decoded_sentence} \n").lower() + if user_input == self.answer.lower(): + self.correctQuestion() + self.nextQuestion() + print("Correct!") + else: + self.nextQuestion() + print("Incorrect!") + + print(f"{self.question_correct}/{self.question_number} correct") + + 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..a7f64ac --- /dev/null +++ b/quiz-game-start/main.py @@ -0,0 +1,22 @@ +from quiz_brain import quizBrain +from data import question_data +from question_model import Question +from cool_quiz import CoolQuizBrain + +question_list = [] + +input_choice = input("Do you want to play normal or fun game? ('normal' / 'fun') \n").lower() + +if input_choice == "normal": + for el in question_data: + question = Question(el["text"], el["answer"]) + question_list.append(question) + + quiz_brain = quizBrain(question_list) + + print(quiz_brain.answercheck()) +else: + cool_quiz = CoolQuizBrain() + print(cool_quiz.answercheck()) + + diff --git a/quiz-game-start/question_model.py b/quiz-game-start/question_model.py new file mode 100644 index 0000000..08e9420 --- /dev/null +++ b/quiz-game-start/question_model.py @@ -0,0 +1,5 @@ +class Question: + def __init__(self, q_text, q_answer): + self.text = q_text + self.answer = q_answer + self.result = {q_text, q_answer} \ No newline at end of file diff --git a/quiz-game-start/quiz_brain.py b/quiz-game-start/quiz_brain.py new file mode 100644 index 0000000..ec19739 --- /dev/null +++ b/quiz-game-start/quiz_brain.py @@ -0,0 +1,30 @@ + +class quizBrain: + def __init__(self, question_data): + self.question_data = question_data + self.question_number = 0 + self.question_correct = 0 + + def correctQuestion(self): + self.question_correct += 1 + + def nextQuestion(self): + self.question_number += 1 + + def answercheck(self): + for question in self.question_data: + + self.question = question.text + user_input = input(f"True or False: {self.question} \n").lower() + self.answer = question.answer.lower() + if user_input == self.answer.lower(): + self.correctQuestion() + self.nextQuestion() + print("Correct!") + else: + self.nextQuestion() + print("Incorrect!") + + print(f"{self.question_correct}/{self.question_number} correct") + + From 0ccb267dade94841def80e475422cde75fc74090 Mon Sep 17 00:00:00 2001 From: storm Date: Fri, 6 Oct 2023 10:39:08 +0700 Subject: [PATCH 5/5] tutrkte --- quiz-game-start/cool_quiz.py | 1 - turtleGameThing/problem1.py | 9 ++++ turtleGameThing/problem2.py | 14 ++++++ turtleGameThing/problem3.py | 18 +++++++ turtleGameThing/problem4.py | 97 ++++++++++++++++++++++++++++++++++++ turtleGameThing/problem5.py | 54 ++++++++++++++++++++ 6 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 turtleGameThing/problem1.py create mode 100644 turtleGameThing/problem2.py create mode 100644 turtleGameThing/problem3.py create mode 100644 turtleGameThing/problem4.py create mode 100644 turtleGameThing/problem5.py diff --git a/quiz-game-start/cool_quiz.py b/quiz-game-start/cool_quiz.py index 3a4907a..973eb95 100644 --- a/quiz-game-start/cool_quiz.py +++ b/quiz-game-start/cool_quiz.py @@ -26,7 +26,6 @@ def nextQuestion(self): def answercheck(self): - for el in self.questions: self.question = el["question"] self.answer = el["correct_answer"] diff --git a/turtleGameThing/problem1.py b/turtleGameThing/problem1.py new file mode 100644 index 0000000..d3722b7 --- /dev/null +++ b/turtleGameThing/problem1.py @@ -0,0 +1,9 @@ +import turtle + +t = turtle.Turtle() + +for _ in range(4): + t.forward(100) + t.right(90) + +turtle.done() \ No newline at end of file diff --git a/turtleGameThing/problem2.py b/turtleGameThing/problem2.py new file mode 100644 index 0000000..8c64900 --- /dev/null +++ b/turtleGameThing/problem2.py @@ -0,0 +1,14 @@ +import turtle + +t = turtle.Turtle() + +t.pensize(2) +t.pencolor("blue") + +for _ in range(10): + t.pendown() + t.forward(10) + t.penup() + t.forward(10) + +turtle.done() \ No newline at end of file diff --git a/turtleGameThing/problem3.py b/turtleGameThing/problem3.py new file mode 100644 index 0000000..219726e --- /dev/null +++ b/turtleGameThing/problem3.py @@ -0,0 +1,18 @@ +import turtle +import random + +t = turtle.Turtle() + +side_length = 100 + +t.speed(10) + +for sides in range(3, 13): + color = ['#{:02X}{:02X}{:02X}'.format(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))][0] + print(color) + t.pencolor(color) + for _ in range(sides): + t.forward(side_length) + t.left(360 / sides) + +turtle.done() diff --git a/turtleGameThing/problem4.py b/turtleGameThing/problem4.py new file mode 100644 index 0000000..e12376c --- /dev/null +++ b/turtleGameThing/problem4.py @@ -0,0 +1,97 @@ +import turtle +import random +from multiprocessing import Pool + +def mainExtra(x): + + + t = turtle.Turtle() + t2 = turtle.Turtle() + + shape_array = ["arrow", "turtle", "circle", "square", "triangle", "classic"] + + step_length = 20 + + def get_random_color(): + return ['#{:02X}{:02X}{:02X}'.format(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))][0] + + t.speed(0) + + for _ in range(1000): + random_shape = shape_array[random.randint(0, len(shape_array) - 1)] + t.shape(random_shape) + + turtle.bgcolor(get_random_color()) + + t.shapesize(random.randint(1, 2)/1) + + t.pensize(random.randint(1, 10)) + t.color(get_random_color()) + t.forward(step_length) + random_angle = [90, 180, -90, 0][random.randint(0, 3)] + t.setheading(random_angle) + + + t2.shape(random_shape) + t2.shapesize(random.randint(1, 2)/1) + t2.pensize(random.randint(1, 10)) + t2.color(get_random_color()) + t2.forward(step_length) + random_angle = [90, 180, -90, 0][random.randint(0, 3)] + t2.setheading(random_angle) + + + + turtle.done() + +def mainExtra2(x): + + + t = turtle.Turtle() + t2 = turtle.Turtle() + + shape_array = ["arrow", "turtle", "circle", "square", "triangle", "classic"] + + step_length = 20 + + def get_random_color(): + return ['#{:02X}{:02X}{:02X}'.format(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))][0] + + t.speed(0) + + for _ in range(1000): + random_shape = shape_array[random.randint(0, len(shape_array) - 1)] + t.shape(random_shape) + + turtle.bgcolor(get_random_color()) + + t.shapesize(random.randint(1, 2)/1) + + t.pensize(random.randint(1, 10)) + t.color(get_random_color()) + t.forward(step_length) + random_angle = [90, 180, -90, 0][random.randint(0, 3)] + t.setheading(random_angle) + + + t2.shape(random_shape) + t2.shapesize(random.randint(1, 2)/1) + t2.pensize(random.randint(1, 10)) + t2.color(get_random_color()) + t2.forward(step_length) + random_angle = [90, 180, -90, 0][random.randint(0, 3)] + t2.setheading(random_angle) + + + + turtle.done() + + +def main(x): + mainExtra(x) + mainExtra2(x) + + +if __name__ == '__main__': + with Pool(2) as p: + print(p.map(main, [1, 2, 3])) \ No newline at end of file diff --git a/turtleGameThing/problem5.py b/turtleGameThing/problem5.py new file mode 100644 index 0000000..6aae083 --- /dev/null +++ b/turtleGameThing/problem5.py @@ -0,0 +1,54 @@ +import turtle +import random +import math + +t = turtle.Turtle() + +turtle.bgcolor("black") + +t.speed(0) +t.width(2) + + +R = 100 +r = 61 +d = 103 + + +def draw_spirograph(R, r, d): + + turn_counter = 0 + + theta = 0 + t.penup() + t.goto(R-r+d*math.cos(math.radians(theta)), d*math.sin(math.radians(theta))) + t.pendown() + + t.color(get_random_color()) + + random_color = get_random_color() + + for _ in range(360): + theta += 1 + + if turn_counter <= 3: + pass + else: + random_color = get_random_color() + t.color(random_color) + turn_counter = 0 + + x = (R - r) * math.cos(math.radians(theta)) + d * math.cos((R - r) * theta / r) + y = (R - r) * math.sin(math.radians(theta)) - d * math.sin((R - r) * theta / r) + t.goto(x, y) + t.color(random_color) + turn_counter += 1 + + +def get_random_color(): + return ['#{:02X}{:02X}{:02X}'.format(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))][0] + + +draw_spirograph(R, r, d) + +turtle.done()