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

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")



43 changes: 42 additions & 1 deletion 2.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,54 @@
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.
"""
...


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.
Expand All @@ -30,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))
29 changes: 29 additions & 0 deletions 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!")
28 changes: 28 additions & 0 deletions oop-coffee-machine-start/main.py
Original file line number Diff line number Diff line change
@@ -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)



34 changes: 34 additions & 0 deletions 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/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
46 changes: 46 additions & 0 deletions quiz-game-start/cool_quiz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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")


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"}
]
22 changes: 22 additions & 0 deletions quiz-game-start/main.py
Original file line number Diff line number Diff line change
@@ -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())


5 changes: 5 additions & 0 deletions quiz-game-start/question_model.py
Original file line number Diff line number Diff line change
@@ -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}
30 changes: 30 additions & 0 deletions quiz-game-start/quiz_brain.py
Original file line number Diff line number Diff line change
@@ -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")


Loading