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
72 changes: 71 additions & 1 deletion 1.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,74 @@
'water': 300,
'milk': 300,
'money': 0,
}
}


class Coffee_Machine:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No underscores neeeded in between of words in class names.

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__()
38 changes: 30 additions & 8 deletions 2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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))
Binary file added oop-coffee-machine-start.zip
Binary file not shown.
29 changes: 29 additions & 0 deletions oop-coffee-machine-start/oop-coffee-machine-start/coffee_maker.py
Original file line number Diff line number Diff line change
@@ -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!")
29 changes: 29 additions & 0 deletions oop-coffee-machine-start/oop-coffee-machine-start/main.py
Original file line number Diff line number Diff line change
@@ -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__()
34 changes: 34 additions & 0 deletions oop-coffee-machine-start/oop-coffee-machine-start/menu.py
Original file line number Diff line number Diff line change
@@ -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.")
39 changes: 39 additions & 0 deletions oop-coffee-machine-start/oop-coffee-machine-start/money_machine.py
Original file line number Diff line number Diff line change
@@ -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
Binary file added quiz-game-start.zip
Binary file not shown.
14 changes: 14 additions & 0 deletions quiz-game-start/data.py
Original file line number Diff line number Diff line change
@@ -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"}
]
18 changes: 18 additions & 0 deletions quiz-game-start/main.py
Original file line number Diff line number Diff line change
@@ -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")
4 changes: 4 additions & 0 deletions quiz-game-start/question_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Question:
def __init__(self, q_text, q_answer):
self.text = q_text
self.answer = q_answer
36 changes: 36 additions & 0 deletions quiz-game-start/quiz_brain.py
Original file line number Diff line number Diff line change
@@ -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")






16 changes: 16 additions & 0 deletions turt/Spirograph.py
Original file line number Diff line number Diff line change
@@ -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()

13 changes: 13 additions & 0 deletions turt/dottedline.py
Original file line number Diff line number Diff line change
@@ -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()

19 changes: 19 additions & 0 deletions turt/randomwalk.py
Original file line number Diff line number Diff line change
@@ -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()
Loading