Skip to content
Merged
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
25 changes: 25 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Ruff Lint and Format

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install Ruff
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Ruff lint
run: ruff check --output-format=github .
- name: Run Ruff format check
run: ruff format --check .
10 changes: 5 additions & 5 deletions black-jack/black_jack.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def value_of_card(card) -> int:
2. 'A' (ace card) = 1
3. '2' - '10' = numerical value.
"""
if card in 'JKQ':
if card in "JKQ":
return 10

if card == 'A':
if card == "A":
return 1

return int(card)
Expand Down Expand Up @@ -62,7 +62,7 @@ def value_of_ace(card_one, card_two) -> int:
total: int = value_of_card(card_one) + value_of_card(card_two)
# Hint: if we already have an ace in hand, then the value for
# the upcoming ace would be 1.
if card_one == 'A' or card_two == 'A':
if card_one == "A" or card_two == "A":
return 1
# The value of the hand with the ace needs to be as high as
# possible without going over 21.
Expand All @@ -89,10 +89,10 @@ def is_blackjack(card_one, card_two) -> bool:
"""
# If a player is dealt an ace (A) and a ten-card (10, K, Q, or J)
# as their first two cards, then the player has a score of 21.
if card_one == 'A' and card_two in ('J', 'Q', 'K', '10'):
if card_one == "A" and card_two in ("J", "Q", "K", "10"):
return True

if card_two == 'A' and card_one in ('J', 'Q', 'K', '10'):
if card_two == "A" and card_one in ("J", "Q", "K", "10"):
return True

return False
Expand Down
3 changes: 1 addition & 2 deletions card-games/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ def get_rounds(number: int) -> list[int]:
return [number, number + 1, number + 2]


def concatenate_rounds(rounds_1: list[int],
rounds_2: list[int]) -> list[int]:
def concatenate_rounds(rounds_1: list[int], rounds_2: list[int]) -> list[int]:
"""
Concatenate two lists of round numbers.

Expand Down
23 changes: 10 additions & 13 deletions chaitanas-colossal-coaster/list_methods.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""Functions to manage and organize queues at Chaitana's roller coaster."""


def add_me_to_the_queue(express_queue: list[str],
normal_queue: list[str],
ticket_type: int,
person_name: str) -> list[str]:
def add_me_to_the_queue(
express_queue: list[str],
normal_queue: list[str],
ticket_type: int,
person_name: str,
) -> list[str]:
"""
Add a person to the 'express' or 'normal' queue depending on the ticket number.

Expand All @@ -22,8 +24,7 @@ def add_me_to_the_queue(express_queue: list[str],
return normal_queue


def find_my_friend(queue: list[str],
friend_name: str) -> int:
def find_my_friend(queue: list[str], friend_name: str) -> int:
"""
Search the queue for a name and return their queue position (index).

Expand All @@ -34,9 +35,7 @@ def find_my_friend(queue: list[str],
return queue.index(friend_name)


def add_me_with_my_friends(queue: list[str],
index: int,
person_name: str) -> list[str]:
def add_me_with_my_friends(queue: list[str], index: int, person_name: str) -> list[str]:
"""
Insert the late arrival's name at a specific index of the queue.

Expand All @@ -49,8 +48,7 @@ def add_me_with_my_friends(queue: list[str],
return queue


def remove_the_mean_person(queue: list[str],
person_name: str) -> list[str]:
def remove_the_mean_person(queue: list[str], person_name: str) -> list[str]:
"""
Remove the mean person from the queue by the provided name.

Expand All @@ -62,8 +60,7 @@ def remove_the_mean_person(queue: list[str],
return queue


def how_many_namefellows(queue: list[str],
person_name: str) -> int:
def how_many_namefellows(queue: list[str], person_name: str) -> int:
"""
Count how many times the provided name appears in the queue.

Expand Down
22 changes: 8 additions & 14 deletions currency-exchange/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"""


def exchange_money(budget: float,
exchange_rate: float) -> float:
def exchange_money(budget: float, exchange_rate: float) -> float:
"""
Return the value of the exchanged currency.

Expand All @@ -24,8 +23,7 @@ def exchange_money(budget: float,
return budget / exchange_rate


def get_change(budget: float,
exchanging_value: float) -> float:
def get_change(budget: float, exchanging_value: float) -> float:
"""
Return the amount of money that "is left" from the budget.

Expand All @@ -36,8 +34,7 @@ def get_change(budget: float,
return budget - exchanging_value # pylint: disable=R0801


def get_value_of_bills(denomination: float,
number_of_bills: float) -> float:
def get_value_of_bills(denomination: float, number_of_bills: float) -> float:
"""
Return only the total value of the bills (excluding fractional amounts)
the booth would give back.
Expand All @@ -52,8 +49,7 @@ def get_value_of_bills(denomination: float,
return denomination * number_of_bills


def get_number_of_bills(amount: float,
denomination: int) -> int:
def get_number_of_bills(amount: float, denomination: int) -> int:
"""
Return the _number of currency bills_ that you can receive within the given _amount_.

Expand All @@ -64,8 +60,7 @@ def get_number_of_bills(amount: float,
return int(amount // denomination)


def get_leftover_of_bills(amount: float,
denomination: int) -> float:
def get_leftover_of_bills(amount: float, denomination: int) -> float:
"""
Return the _leftover amount_ that cannot be returned from your starting _amount_
given the denomination of bills.
Expand All @@ -78,10 +73,9 @@ def get_leftover_of_bills(amount: float,


# pylint: disable=R0801
def exchangeable_value(budget: float,
exchange_rate: float,
spread: int,
denomination: int) -> int:
def exchangeable_value(
budget: float, exchange_rate: float, spread: int, denomination: int
) -> int:
"""
Return the maximum value of the new currency after calculating
the *exchange rate* plus the *spread*.
Expand Down
6 changes: 3 additions & 3 deletions ghost-gobble-arcade-game/arcade_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def lose(power_pellet_active: bool, touching_ghost: bool) -> bool:
return touching_ghost and not power_pellet_active


def win(has_eaten_all_dots: bool,
power_pellet_active: bool,
touching_ghost: bool) -> bool:
def win(
has_eaten_all_dots: bool, power_pellet_active: bool, touching_ghost: bool
) -> bool:
"""
Trigger the victory event when all dots have been eaten.

Expand Down
2 changes: 1 addition & 1 deletion grains/grains.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ def total() -> int:
:rtype: int
"""
# return sum(square(sqr) for sqr in range(1, 65))
return 2 ** 64 - 1
return 2**64 - 1
7 changes: 3 additions & 4 deletions guidos-gorgeous-lasagna/lasagna.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
of a module and its functions and/or classes.
"""


EXPECTED_BAKE_TIME: int = 40
PREPARATION_TIME: int = 2

Expand Down Expand Up @@ -45,8 +44,7 @@ def preparation_time_in_minutes(number_of_layers: int) -> int:
return int(PREPARATION_TIME * number_of_layers)


def elapsed_time_in_minutes(number_of_layers: int,
elapsed_bake_time: int) -> int:
def elapsed_time_in_minutes(number_of_layers: int, elapsed_bake_time: int) -> int:
"""
Calculate elapsed time in minutes.

Expand All @@ -62,4 +60,5 @@ def elapsed_time_in_minutes(number_of_layers: int,
:rtype: int
"""
return preparation_time_in_minutes(number_of_layers=number_of_layers) + (
EXPECTED_BAKE_TIME - bake_time_remaining(elapsed_bake_time))
EXPECTED_BAKE_TIME - bake_time_remaining(elapsed_bake_time)
)
2 changes: 1 addition & 1 deletion hello-world/hello_world.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# pylint: disable=C0116, C0114
def hello():
return 'Hello, World!'
return "Hello, World!"
10 changes: 5 additions & 5 deletions little-sisters-vocab/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def add_prefix_un(word: str) -> str:
:param word: str - containing the root word.
:return: str - of root word prepended with 'un'.
"""
return f'un{word}'
return f"un{word}"


def make_word_groups(vocab_words: list[str]) -> str:
Expand All @@ -27,7 +27,7 @@ def make_word_groups(vocab_words: list[str]) -> str:
For example: list('en', 'close', 'joy', 'lighten'),
produces the following string: 'en :: enclose :: enjoy :: enlighten'.
"""
return f' :: {vocab_words[0]}'.join(vocab_words)
return f" :: {vocab_words[0]}".join(vocab_words)


def remove_suffix_ness(word: str) -> str:
Expand All @@ -39,7 +39,7 @@ def remove_suffix_ness(word: str) -> str:

For example: "heaviness" becomes "heavy", but "sadness" becomes "sad".
"""
return f'{word[:-5]}y' if word[-5] == 'i' else word[:-4]
return f"{word[:-5]}y" if word[-5] == "i" else word[:-4]


def adjective_to_verb(sentence: str, index: int) -> str:
Expand All @@ -53,5 +53,5 @@ def adjective_to_verb(sentence: str, index: int) -> str:
For example, ("It got dark as the sun set.", 2) becomes "darken".
"""
words: list[str] = sentence.split()
word: str = words[index].strip('.,!?;:')
return f'{word}en'
word: str = words[index].strip(".,!?;:")
return f"{word}en"
14 changes: 8 additions & 6 deletions making-the-grade/loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def count_failed_students(student_scores: list) -> int:
return len([score for score in student_scores if score <= 40.0]) # pylint: disable=R0801


def above_threshold(student_scores: list,
threshold: int) -> list:
def above_threshold(student_scores: list, threshold: int) -> list:
"""
Filter out above threshold scores.

Expand Down Expand Up @@ -55,17 +54,20 @@ def letter_grades(highest: int) -> list:


# pylint: disable=R0801
def student_ranking(student_scores: list,
student_names: list) -> list[str]:
def student_ranking(student_scores: list, student_names: list) -> list[str]:
"""
Organize the student's rank, name, and grade information in descending order.

:param student_scores: list - of scores in descending order.
:param student_names: list - of string names by exam score in descending order.
:return: list - of strings in format ["<rank>. <student name>: <score>"].
"""
return [f"{i}. {name}: {score}" for i, score, name in zip(
range(1, len(student_scores) + 1), student_scores, student_names)]
return [
f"{i}. {name}: {score}"
for i, score, name in zip(
range(1, len(student_scores) + 1), student_scores, student_names
)
]


# pylint: disable=R0801
Expand Down
22 changes: 13 additions & 9 deletions meltdown-mitigation/conditionals.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ def is_criticality_balanced(temperature, neutrons_emitted) -> bool:
- The number of neutrons emitted per second is greater than 500.
- The product of temperature and neutrons emitted per second is less than 500000.
"""
return temperature < 800 and neutrons_emitted > 500 and (temperature * neutrons_emitted) < 500000
return (
temperature < 800
and neutrons_emitted > 500
and (temperature * neutrons_emitted) < 500000
)


def reactor_efficiency(voltage, current, theoretical_max_power) -> str:
Expand All @@ -39,18 +43,18 @@ def reactor_efficiency(voltage, current, theoretical_max_power) -> str:
where generated power = voltage * current
"""
generated_power = voltage * current
efficiency = (generated_power/theoretical_max_power)*100
efficiency = (generated_power / theoretical_max_power) * 100

if efficiency < 30:
return 'black'
return "black"

if 30 <= efficiency < 60:
return 'red'
return "red"

if 60 <= efficiency < 80:
return 'orange'
return "orange"

return 'green'
return "green"


def fail_safe(temperature, neutrons_produced_per_second, threshold) -> str:
Expand All @@ -70,9 +74,9 @@ def fail_safe(temperature, neutrons_produced_per_second, threshold) -> str:
thr_percent = threshold / 100

if thr_percent - 10 <= current_state <= thr_percent + 10:
return 'NORMAL'
return "NORMAL"

if current_state < thr_percent - 10:
return 'LOW'
return "LOW"

return 'DANGER'
return "DANGER"
Loading