-
Notifications
You must be signed in to change notification settings - Fork 12
done #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pankace
wants to merge
9
commits into
krepysh:master
Choose a base branch
from
pankace:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
done #2
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2f5e0c9
this coffeeeeeeeeeeeeeeeeeeeeeeeeee
pankace 7158878
this coffeeeeeeeeeeeeeeeeeeeeeeeeee
pankace 625a3f5
this coffeeeeeeeeeeeeeeeeeeeeeeeeee
pankace 7b17fea
toooooooooooooo
pankace 6741931
dsjfsjkooooooooo
pankace 9ea93f0
dsjfsjkooooooooo
pankace 137ed31
oompaloompa
pankace dbf26b3
quiz
pankace d9e964c
turt
pankace File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
29 changes: 29 additions & 0 deletions
29
oop-coffee-machine-start/oop-coffee-machine-start/coffee_maker.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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__() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
39
oop-coffee-machine-start/oop-coffee-machine-start/money_machine.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"} | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.