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
2 changes: 1 addition & 1 deletion 03_Animal/python/animal.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def main() -> None:
# Main loop of game
print_intro()
while (
keep_playing := parse_input(
parse_input(
"Are you thinking of an animal? ", True, root
)
== "y"
Expand Down
10 changes: 5 additions & 5 deletions 07_Basketball/python/basketball.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def dartmouth_jump_shot(self) -> None:
else:
print("Shot is off target.")
if self.defense / 6 * random.random() > 0.45:
print(f"Rebound to {self.opponent}" + "\n")
print(f"Rebound to {self.opponent}\n")
self.opponent_ball()
else:
print("Dartmouth controls the rebound.")
Expand Down Expand Up @@ -185,7 +185,7 @@ def dartmouth_non_jump_shot(self) -> None:
if 7 / self.defense * random.random() > 0.925:
print("Charging foul. Dartmouth loses the ball.\n")
else:
print(f"Shot blocked. {self.opponent}" + "'s ball.\n")
print(f"Shot blocked. {self.opponent}'s ball.\n")
else:
self.foul_shots(1)
self.opponent_ball()
Expand Down Expand Up @@ -270,7 +270,7 @@ def opponent_jumpshot(self) -> None:
or self.defense != 6
and random.random() <= 0.5
):
print(f"Pass back to {self.opponent}" + " guard.\n")
print(f"Pass back to {self.opponent} guard.\n")
self.opponent_ball()
elif self.defense == 6 and random.random() > 0.75:
print("Ball stolen. Easy lay up for Dartmouth.")
Expand Down Expand Up @@ -310,14 +310,14 @@ def opponent_non_jumpshot(self) -> None:
and random.random() <= 0.75
and random.random() <= 0.5
):
print(f"Pass back to {self.opponent}" + " guard.\n")
print(f"Pass back to {self.opponent} guard.\n")
self.opponent_ball()
elif self.defense == 6 and random.random() > 0.75:
print("Ball stolen. Easy lay up for Dartmouth.")
self.add_points(1, 2)
self.opponent_ball()
else:
print(f"Pass back to {self.opponent}" + " guard\n")
print(f"Pass back to {self.opponent} guard\n")
self.opponent_ball()
else:
print("Dartmouth controls the rebound.\n")
Expand Down
2 changes: 1 addition & 1 deletion 17_Bullfight/python/bullfight.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def determine_player_kills(
print(f"THE {player_type}{plural_form} DID A {job_qualities[job_quality]} JOB.")
if job_quality >= 4:
if job_quality == 5:
if player_was_killed := random.choice([True, False]):
if random.choice([True, False]):
print(f"ONE OF THE {player_type}{plural_form} WAS KILLED.")
else:
if player_type != "TOREAD":
Expand Down
24 changes: 12 additions & 12 deletions 49_Hockey/python/hockey.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def print_header() -> None:


def instructions() -> None:
if wants_it := ask_binary(
if ask_binary(
"WOULD YOU LIKE THE INSTRUCTIONS? ", "ANSWER YES OR NO!!"
):
print()
Expand Down Expand Up @@ -229,7 +229,7 @@ def team2_action(
z1 = 3
elif pass_value == 2:
print("IT'S A ' 3 ON 2 '!\n")
print(f"ONLY {team_a.players[3]} AND {team_a.players[4]}" + " ARE BACK.\n")
print(f"ONLY {team_a.players[3]} AND {team_a.players[4]} ARE BACK.\n")
print(
team_b.players[player_index[j - 2]]
+ " GIVES OFF TO "
Expand Down Expand Up @@ -374,7 +374,7 @@ def handle_hit(
else:
print(f"{team_b.name}: {team_b.score}\t{team_a.name}: {team_a.score}\n")
team = team_a if controlling_team == 1 else team_b
print(f"GOAL SCORED BY: {team.players[goal_player]}" + "\n")
print(f"GOAL SCORED BY: {team.players[goal_player]}\n")
if goal_assistant1 != 0:
if goal_assistant2 != 0:
print(
Expand Down Expand Up @@ -402,16 +402,16 @@ def handle_miss(
saving_player = randint(1, 7)
if controlling_team == 1:
if saving_player == 1:
print(f"KICK SAVE AND A BEAUTY BY {team_b.players[5]}" + "\n")
print(f"CLEARED OUT BY {team_b.players[3]}" + "\n")
print(f"KICK SAVE AND A BEAUTY BY {team_b.players[5]}\n")
print(f"CLEARED OUT BY {team_b.players[3]}\n")
remaining_time -= 1
return ("continue", remaining_time)
if saving_player == 2:
print(f"WHAT A SPECTACULAR GLOVE SAVE BY {team_b.players[5]}" + "\n")
print(f"AND {team_b.players[5]}" + " GOLFS IT INTO THE CROWD\n")
print(f"WHAT A SPECTACULAR GLOVE SAVE BY {team_b.players[5]}\n")
print(f"AND {team_b.players[5]} GOLFS IT INTO THE CROWD\n")
return ("break", remaining_time)
if saving_player == 3:
print(f"SKATE SAVE ON A LOW STEAMER BY {team_b.players[5]}" + "\n")
print(f"SKATE SAVE ON A LOW STEAMER BY {team_b.players[5]}\n")
remaining_time -= 1
return ("continue", remaining_time)
if saving_player == 4:
Expand Down Expand Up @@ -447,20 +447,20 @@ def handle_miss(
print("ON THE LOOSE PUCK!\n")
return ("break", remaining_time)
if saving_player == 3:
print(f"SKATE SAVE BY {team_a.players[5]}" + "\n")
print(f"SKATE SAVE BY {team_a.players[5]}\n")
print(team_a.players[5] + " WHACKS THE LOOSE PUCK INTO THE STANDS\n")
return ("break", remaining_time)
if saving_player == 4:
print(f"STICK SAVE BY {team_a.players[5]}" + " AND HE CLEARS IT OUT HIMSELF\n")
print(f"STICK SAVE BY {team_a.players[5]} AND HE CLEARS IT OUT HIMSELF\n")
remaining_time -= 1
return ("continue", remaining_time)
if saving_player == 5:
print(f"KICKED OUT BY {team_a.players[5]}" + "\n")
print(f"KICKED OUT BY {team_a.players[5]}\n")
print("AND IT REBOUNDS ALL THE WAY TO CENTER ICE\n")
remaining_time -= 1
return ("continue", remaining_time)
if saving_player == 6:
print(f"GLOVE SAVE {team_a.players[5]}" + " AND HE HANGS ON\n")
print(f"GLOVE SAVE {team_a.players[5]} AND HE HANGS ON\n")
return ("break", remaining_time)
return ("continue", remaining_time)

Expand Down
2 changes: 1 addition & 1 deletion 59_Lunar_LEM_Rocket/python/lunar.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def run_simulation() -> None:
return

if capsule.velocity > 0 and new_state.velocity < 0:
if landed := handle_flyaway(sim_clock, capsule):
if handle_flyaway(sim_clock, capsule):
process_final_tick(delta_t, sim_clock, capsule)
return

Expand Down
2 changes: 1 addition & 1 deletion 64_Nicomachus/python/nicomachus.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def play_game() -> None:

print(f"YOUR NUMBER WAS {d}, RIGHT?")

if response := get_yes_or_no():
if get_yes_or_no():
print("HOW ABOUT THAT!!")
else:
print("I FEEL YOUR ARITHMETIC IS IN ERROR.")
Expand Down
6 changes: 3 additions & 3 deletions 65_Nim/python/Traditional_NIM.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ def main() -> None:

# Start game loop
input("\nPress Enter to start the Game:\n")
end = False

while True:
game.print_pegs()

# Players Move
command = input("\nYOUR MOVE - Number of PILE, Number of Object? ")
game.remove_pegs(command)
if end := game.check_for_win():
if game.check_for_win():
print("\nPlayer Wins the Game, Congratulations!!")
input("\nPress any key to exit")
break
Expand All @@ -96,7 +96,7 @@ def main() -> None:
f"\nA.I MOVE - A.I Removed {ai_command[1]} pegs from Pile {ai_command[0]}"
)
game.remove_pegs(f"{str(ai_command[0])},{str(ai_command[1])}")
if end := game.check_for_win():
if game.check_for_win():
print("\nComputer Wins the Game, Better Luck Next Time\n")
input("Press any key to exit")
break
Expand Down
2 changes: 1 addition & 1 deletion 69_Pizza/python/pizza.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def main() -> None:

player_name = print_instructions()

if more_directions := yes_no_prompt("DO YOU NEED MORE DIRECTIONS?"):
if yes_no_prompt("DO YOU NEED MORE DIRECTIONS?"):
print_more_directions(player_name)

understand = yes_no_prompt("UNDERSTAND?")
Expand Down
14 changes: 7 additions & 7 deletions 72_Queen/python/queen.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ def num_to_loc(num: int) -> Tuple[int, int]:
)

# These are the places that the computer will always try to move into.
COMPUTER_PREF_MOVES: Final[
FrozenSet[Tuple[int, int]]
] = COMPUTER_SAFE_SPOTS | frozenset([WIN_LOC])
COMPUTER_PREF_MOVES: Final[FrozenSet[Tuple[int, int]]] = (
COMPUTER_SAFE_SPOTS | frozenset([WIN_LOC])
)

# These are the locations (not including the win location) from which either player can
# force a win (but the computer will always choose one of the COMPUTER_PREF_MOVES).
Expand Down Expand Up @@ -171,10 +171,10 @@ def get_move(current_loc: Optional[Tuple[int, int]]) -> Tuple[int, int]:
"WHERE WOULD YOU LIKE TO START? "
)
elif (
(new_row == row and new_col < col) # move left
or (new_col == col and new_row > row) # move down
or (new_row - row == col - new_col) # move diag left and down
) and (not FIX_BOARD_BUG or (new_col >= 0 and new_row < 8)):
(new_row == row and new_col < col) # move left
or (new_col == col and new_row > row) # move down
or (new_row - row == col - new_col) # move diag left and down
) and (not FIX_BOARD_BUG or (new_col >= 0 and new_row < 8)):
return new_row, new_col
else:
prompt = "Y O U C H E A T . . . TRY AGAIN? "
Expand Down
2 changes: 1 addition & 1 deletion 89_Tic-Tac-Toe/python/TicTacToe_Hard.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def display(game: TicTacToe) -> None:
if game.board[i][game.dim_sz - 1] == "blur":
line1 = line1 + " \n"
else:
line1 = f"{line1} {game.board[i][game.dim_sz - 1]}" + " \n"
line1 = f"{line1} {game.board[i][game.dim_sz - 1]} \n"
print(line1, "\n\n")


Expand Down
Loading