Skip to content

Commit 859546b

Browse files
committed
refactor
1 parent 1d740e9 commit 859546b

File tree

144 files changed

+13209
-9570
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+13209
-9570
lines changed

day016/coffee_maker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class CoffeeMaker:
22
"""Models the machine that makes the coffee"""
3+
34
def __init__(self):
45
self.resources = {
56
"water": 300,
@@ -26,4 +27,4 @@ def make_coffee(self, order):
2627
"""Deducts the required ingredients from the resources."""
2728
for item in order.ingredients:
2829
self.resources[item] -= order.ingredients[item]
29-
print(f"Here is your {order.name} ☕️. Enjoy!")
30+
print(f"Here is your {order.name} ☕️. Enjoy!")

day016/main.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
while True:
1515
options = menu.get_items()
1616
choice = input(f"What would you like? ({options}): ").lower()
17-
if choice == 'off':
17+
if choice == "off":
1818
print("Have a good day!")
1919
break
20-
elif choice == 'report':
20+
elif choice == "report":
2121
coffee_maker.report()
2222
money_machine.report()
2323
else:
2424
drink = menu.find_drink(choice)
25-
if coffee_maker.is_resource_sufficient(drink) and money_machine.make_payment(drink.cost):
26-
coffee_maker.make_coffee(drink)
25+
if coffee_maker.is_resource_sufficient(drink) and money_machine.make_payment(
26+
drink.cost
27+
):
28+
coffee_maker.make_coffee(drink)

day016/menu.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
class MenuItem:
22
"""Models each Menu Item."""
3+
34
def __init__(self, name, water, milk, coffee, cost):
45
self.name = name
56
self.cost = cost
6-
self.ingredients = {
7-
"water": water,
8-
"milk": milk,
9-
"coffee": coffee
10-
}
7+
self.ingredients = {"water": water, "milk": milk, "coffee": coffee}
118

129

1310
class Menu:
1411
"""Models the Menu with drinks."""
12+
1513
def __init__(self):
1614
self.menu = [
1715
MenuItem(name="latte", water=200, milk=150, coffee=24, cost=2.5),
@@ -28,4 +26,4 @@ def find_drink(self, order_name):
2826
for item in self.menu:
2927
if item.name == order_name:
3028
return item
31-
print("Sorry that item is not available.")
29+
print("Sorry that item is not available.")

day016/money_machine.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
class MoneyMachine:
22
CURRENCY = "$"
33

4-
COIN_VALUES = {
5-
"quarters": 0.25,
6-
"dimes": 0.10,
7-
"nickles": 0.05,
8-
"pennies": 0.01
9-
}
4+
COIN_VALUES = {"quarters": 0.25, "dimes": 0.10, "nickles": 0.05, "pennies": 0.01}
105

116
def __init__(self):
127
self.profit = 0
@@ -20,7 +15,9 @@ def process_coins(self):
2015
"""Returns the total calculated from coins inserted."""
2116
print("Please insert coins.")
2217
for coin in self.COIN_VALUES:
23-
self.money_received += int(input(f"How many {coin}? ")) * self.COIN_VALUES[coin]
18+
self.money_received += (
19+
int(input(f"How many {coin}? ")) * self.COIN_VALUES[coin]
20+
)
2421
return self.money_received
2522

2623
def make_payment(self, cost):
@@ -35,4 +32,4 @@ def make_payment(self, cost):
3532
else:
3633
print("Sorry that's not enough money. Money refunded.")
3734
self.money_received = 0
38-
return False
35+
return False

day017/data.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
question_data = [
22
{"text": "A slug's blood is green.", "answer": "True"},
33
{"text": "The loudest animal is the African Elephant.", "answer": "False"},
4-
{"text": "Approximately one quarter of human bones are in the feet.", "answer": "True"},
5-
{"text": "The total surface area of a human lungs is the size of a football pitch.", "answer": "True"},
6-
{"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"},
7-
{"text": "In London, UK, if you happen to die in the House of Parliament, you are entitled to a state funeral.", "answer": "False"},
4+
{
5+
"text": "Approximately one quarter of human bones are in the feet.",
6+
"answer": "True",
7+
},
8+
{
9+
"text": "The total surface area of a human lungs is the size of a football pitch.",
10+
"answer": "True",
11+
},
12+
{
13+
"text": "In West Virginia, USA, if you accidentally hit an animal with your car, you are free to take it home to eat.",
14+
"answer": "True",
15+
},
16+
{
17+
"text": "In London, UK, if you happen to die in the House of Parliament, you are entitled to a state funeral.",
18+
"answer": "False",
19+
},
820
{"text": "It is illegal to pee in the Ocean in Portugal.", "answer": "True"},
921
{"text": "You can lead a cow down stairs but not up stairs.", "answer": "False"},
1022
{"text": "Google was originally called 'Backrub'.", "answer": "True"},
1123
{"text": "Buzz Aldrin's mother's maiden name was 'Moon'.", "answer": "True"},
12-
{"text": "No piece of square dry paper can be folded in half more than 7 times.", "answer": "False"},
13-
{"text": "A few ounces of chocolate can to kill a small dog.", "answer": "True"}
24+
{
25+
"text": "No piece of square dry paper can be folded in half more than 7 times.",
26+
"answer": "False",
27+
},
28+
{"text": "A few ounces of chocolate can to kill a small dog.", "answer": "True"},
1429
]

day017/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@
1414
while quiz.questions_left():
1515
quiz.next_question()
1616

17-
print(f"Thanks for completing the trivia. Your final score is: {quiz.score}/{quiz.question_number}.")
17+
print(
18+
f"Thanks for completing the trivia. Your final score is: {quiz.score}/{quiz.question_number}."
19+
)

day017/question_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
class Question:
22
def __init__(self, text, answer):
33
self.text = text
4-
self.answer = answer
4+
self.answer = answer

day017/quiz_brain.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ def questions_left(self):
1010
def next_question(self):
1111
current_question = self.question_list[self.question_number]
1212
self.question_number += 1
13-
user_answer = input(f"Q.{self.question_number}: {current_question.text} (True/False): ")
13+
user_answer = input(
14+
f"Q.{self.question_number}: {current_question.text} (True/False): "
15+
)
1416
self.check_answer(user_answer, current_question.answer)
1517

1618
def check_answer(self, user_answer, correct_answer):
@@ -23,4 +25,3 @@ def check_answer(self, user_answer, correct_answer):
2325
print(f"The correct answer was: {correct_answer}.")
2426
print(f"Your current score is: {self.score}/{self.question_number}.")
2527
print("\n")
26-

day018/draw_shapes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
tom.color(random.random(), random.random(), random.random())
88
for _ in range(i):
99
tom.forward(100)
10-
tom.right(360/i)
10+
tom.right(360 / i)

day018/main.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,35 @@
88
dot.penup()
99
dot.hideturtle()
1010

11-
color_list = [(202, 164, 109), (238, 240, 245), (150, 75, 49), (223, 201, 135), (52, 93, 124), (172, 154, 40), (140, 30, 19), (133, 163, 185), (198, 91, 71), (46, 122, 86), (72, 43, 35), (145, 178, 148), (13, 99, 71),
12-
(233, 175, 164), (161, 142, 158), (105, 74, 77), (55, 46, 50), (183, 205, 171), (36, 60, 74), (18, 86, 90), (81, 148, 129), (148, 17, 20), (14, 70, 64), (30, 68, 100), (107, 127, 153), (174, 94, 97), (176, 192, 209)]
11+
color_list = [
12+
(202, 164, 109),
13+
(238, 240, 245),
14+
(150, 75, 49),
15+
(223, 201, 135),
16+
(52, 93, 124),
17+
(172, 154, 40),
18+
(140, 30, 19),
19+
(133, 163, 185),
20+
(198, 91, 71),
21+
(46, 122, 86),
22+
(72, 43, 35),
23+
(145, 178, 148),
24+
(13, 99, 71),
25+
(233, 175, 164),
26+
(161, 142, 158),
27+
(105, 74, 77),
28+
(55, 46, 50),
29+
(183, 205, 171),
30+
(36, 60, 74),
31+
(18, 86, 90),
32+
(81, 148, 129),
33+
(148, 17, 20),
34+
(14, 70, 64),
35+
(30, 68, 100),
36+
(107, 127, 153),
37+
(174, 94, 97),
38+
(176, 192, 209),
39+
]
1340
dot.setheading(225)
1441
dot.forward(300)
1542
dot.setheading(0)
@@ -27,4 +54,4 @@
2754
dot.setheading(0)
2855

2956
screen = turtle_module.Screen()
30-
screen.exitonclick()
57+
screen.exitonclick()

day018/random_walk.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
tom.pensize(10)
1010
tom.speed("fastest")
1111

12+
1213
def moveRandom(turtle):
1314
turtle.forward(-20)
1415
turtle.setheading(random.choice(choice))
@@ -18,4 +19,4 @@ def moveRandom(turtle):
1819
tom.pencolor(random.random(), random.random(), random.random())
1920
moveRandom(tom)
2021

21-
screen.exitonclick()
22+
screen.exitonclick()

day018/spirograph.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77

88
tom.speed("fastest")
99

10+
1011
def random_color():
1112
r = random.randint(0, 255)
1213
g = random.randint(0, 255)
1314
b = random.randint(0, 255)
1415
return r, g, b
1516

17+
1618
for index in range(0, 361, 3):
1719
tom.color(random_color())
1820
tom.setheading(index)
1921
tom.circle(100)
2022

21-
screen.exitonclick()
23+
screen.exitonclick()

day019/etch_a_sketch.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,32 @@
33
tom = Turtle()
44
screen = Screen()
55

6+
67
def move_forwards():
78
tom.forward(10)
89

10+
911
def move_backwards():
1012
tom.backward(10)
1113

14+
1215
def turn_left():
1316
tom.left(10)
1417

18+
1519
def turn_right():
1620
tom.right(10)
1721

22+
1823
def clear_screen():
1924
tom.reset()
2025

26+
2127
screen.listen()
2228
screen.onkey(move_forwards, "w")
2329
screen.onkey(move_backwards, "s")
2430
screen.onkey(turn_left, "a")
2531
screen.onkey(turn_right, "d")
2632
screen.onkey(clear_screen, "c")
2733

28-
screen.exitonclick()
34+
screen.exitonclick()

day019/main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33

44
screen = Screen()
55
screen.setup(width=800, height=600)
6-
screen.bgpic('road.gif')
6+
screen.bgpic("road.gif")
77

88
ALIGN = "right"
99
FONT = ("Courier", 28, "bold")
1010

1111
y_positions = [-260, -172, -85, 2, 85, 172, 260]
1212
colors = ["white", "red", "orange", "pink", "tomato", "dodgerblue", "yellow"]
1313
all_turtle = []
14-
user_bet = screen.textinput('Enter your bet', prompt='Which turtle (color): ')
14+
user_bet = screen.textinput("Enter your bet", prompt="Which turtle (color): ")
1515

1616
for index in range(7):
1717
new_turtle = Turtle(shape="turtle")
1818
new_turtle.shapesize(2)
19-
new_turtle.speed('fastest')
19+
new_turtle.speed("fastest")
2020
new_turtle.penup()
2121
new_turtle.goto(x=-350, y=y_positions[index])
2222
new_turtle.color(colors[index])
@@ -30,10 +30,10 @@
3030
is_on = False
3131
winner = turtle.pencolor()
3232
if winner == user_bet:
33-
turtle.write(f'Winner! The {winner} is winner', font=FONT, align=ALIGN)
33+
turtle.write(f"Winner! The {winner} is winner", font=FONT, align=ALIGN)
3434
else:
35-
turtle.write(f'Lost! The {winner} is winner', font=FONT, align=ALIGN)
35+
turtle.write(f"Lost! The {winner} is winner", font=FONT, align=ALIGN)
3636
random_pace = random.randint(0, 7)
3737
turtle.forward(random_pace)
3838

39-
screen.exitonclick()
39+
screen.exitonclick()

day020/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
time.sleep(0.1)
2323
snake.move()
2424

25-
screen.exitonclick()
25+
screen.exitonclick()

day020/snake.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
LEFT = 180
88
RIGHT = 0
99

10+
1011
class Snake:
1112
def __init__(self):
1213
self.segments = []
@@ -42,4 +43,4 @@ def left(self):
4243

4344
def right(self):
4445
if self.head.heading() != LEFT:
45-
self.head.setheading(RIGHT)
46+
self.head.setheading(RIGHT)

day021/food.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from turtle import Turtle
22
from random import randint
33

4+
45
class Food(Turtle):
56
def __init__(self):
67
super().__init__()
@@ -10,8 +11,8 @@ def __init__(self):
1011
self.color("blue")
1112
self.speed("fastest")
1213
self.refresh()
13-
14+
1415
def refresh(self):
1516
random_x = randint(-14, 14) * 20
1617
random_y = randint(-14, 14) * 20
17-
self.goto(random_x, random_y)
18+
self.goto(random_x, random_y)

0 commit comments

Comments
 (0)