diff --git a/.github/workflows/check-python.yml b/.github/workflows/check-python.yml index 6e40a06f..48928775 100644 --- a/.github/workflows/check-python.yml +++ b/.github/workflows/check-python.yml @@ -28,4 +28,4 @@ jobs: mypy . --exclude 79_Slalom --exclude 27_Civil_War --exclude 38_Fur_Trader --exclude 81_Splat --exclude 09_Battle --exclude 40_Gomoko --exclude 36_Flip_Flop --exclude 43_Hammurabi --exclude 04_Awari --exclude 78_Sine_Wave --exclude 77_Salvo --exclude 34_Digits --exclude 17_Bullfight --exclude 16_Bug - name: Test with flake8 run: | - flake8 . --ignore E501,W504,W503,F541,E203,W291,E711,F821,F401,E402,E731 + flake8 . --ignore E501,W503,E203,E731 diff --git a/02_Amazing/python/test_amazing.py b/02_Amazing/python/test_amazing.py index 4e860d23..774404cc 100644 --- a/02_Amazing/python/test_amazing.py +++ b/02_Amazing/python/test_amazing.py @@ -3,7 +3,7 @@ from amazing import build_maze, welcome_header def test_welcome_header(capsys): - assert welcome_header() == None + assert welcome_header() is None out, err = capsys.readouterr() assert out == ( " AMAZING PROGRAM\n" diff --git a/09_Battle/python/battle.py b/09_Battle/python/battle.py index 93d24fe9..0aa6127c 100644 --- a/09_Battle/python/battle.py +++ b/09_Battle/python/battle.py @@ -112,7 +112,7 @@ def main() -> None: sea = tuple([0 for _ in range(SEA_WIDTH)] for _ in range(SEA_WIDTH)) setup_ships(sea) print( - f""" + """ BATTLE CREATIVE COMPUTING MORRISTOWN, NEW JERSEY diff --git a/16_Bug/python/bug-overengineered.py b/16_Bug/python/bug-overengineered.py index bc4dee1b..cafd2124 100644 --- a/16_Bug/python/bug-overengineered.py +++ b/16_Bug/python/bug-overengineered.py @@ -133,7 +133,7 @@ def update_game(data, action): # the new part depends on and doesn't have enough of the part already overMaxParts = part_type.count < part_count + 1 missingPartDep = ( - part_type.depends != None and parts[part_type.depends] == 0 + part_type.depends is not None and parts[part_type.depends] == 0 ) if not overMaxParts and not missingPartDep: diff --git a/27_Civil_War/python/Civilwar.py b/27_Civil_War/python/Civilwar.py index 81a3dc9e..4878bffa 100644 --- a/27_Civil_War/python/Civilwar.py +++ b/27_Civil_War/python/Civilwar.py @@ -190,20 +190,21 @@ def main(): union_strategy_index = 0 u = 0 u2 = 0 + random_nb = 0 while True: print() print() print() - a = int(input("WHICH BATTLE DO YOU WISH TO SIMULATE? ")) - if a < 1 or a > 14: + simulated_battle_index = int(input("WHICH BATTLE DO YOU WISH TO SIMULATE? ")) + if simulated_battle_index < 1 or simulated_battle_index > 14: break - if a != 0 or r == 0: - cs = historical_data[a][0] - m1 = historical_data[a][1] - m2 = historical_data[a][2] - c1 = historical_data[a][3] - c2 = historical_data[a][4] - m = historical_data[a][5] + if simulated_battle_index != 0 or random_nb == 0: + cs = historical_data[simulated_battle_index][0] + m1 = historical_data[simulated_battle_index][1] + m2 = historical_data[simulated_battle_index][2] + c1 = historical_data[simulated_battle_index][3] + c2 = historical_data[simulated_battle_index][4] + m = historical_data[simulated_battle_index][5] u = 0 # Inflation calc i1 = 10 + (line - w) * 2 @@ -228,7 +229,7 @@ def main(): print() print(f"THIS IS THE BATTLE OF {cs}") if xs != "NO": - print("\n".join(battles[a - 1])) + print("\n".join(battles[simulated_battle_index - 1])) else: print(cs + " INSTANT REPLAY") @@ -318,7 +319,7 @@ def main(): print("THE CONFEDERACY HAS SURRENDERED.") break # Union strategy is computer chosen - if a == 0: + if simulated_battle_index == 0: while True: union_strategy_index = int(input("UNION STRATEGY IS ")) if union_strategy_index > 0 and union_strategy_index < 5: @@ -326,12 +327,12 @@ def main(): print("ENTER 1, 2, 3, OR 4 (USUALLY PREVIOUS UNION STRATEGY)") else: s0 = 0 - r = math.random() * 100 + random_nb = math.random() * 100 for i in range(1, 5): s0 += sa[i] # If actual strategy info is in program data statements # then r-100 is extra weight given to that strategy. - if r < s0: + if random_nb < s0: break union_strategy_index = i print(union_strategy_index) @@ -347,7 +348,7 @@ def main(): print("YOUR STRATEGY ? ", end="") if i == 2: union_strategy_index = strategy_index - strategy_index = previous_strategy + strategy_index = previous_strategy # noqa: F821 if union_strategy_index != 5: break else: @@ -407,15 +408,15 @@ def main(): w0 += 1 elif u == 1 or (u != 1 and u2 != 1 and c5 + e > c6 + e2): print("THE UNION WINS " + str(cs)) - if a != 0: + if simulated_battle_index != 0: line += 1 else: print("THE CONFEDERACY WINS " + str(cs)) - if a != 0: + if simulated_battle_index != 0: w += 1 # Lines 2530 to 2590 from original are unreachable. - if a != 0: + if simulated_battle_index != 0: t1 += c5 + e t2 += c6 + e2 p1 += c1 diff --git a/29_Craps/python/craps.py b/29_Craps/python/craps.py index 1f788ba8..9ac079b2 100644 --- a/29_Craps/python/craps.py +++ b/29_Craps/python/craps.py @@ -74,8 +74,8 @@ while play_again: play_again = m == "5" if winnings < 0: - print(f"Too bad, you are in the hole. Come again.") + print("Too bad, you are in the hole. Come again.") elif winnings > 0: - print(f"Congratulations---you came out a winner. Come again.") + print("Congratulations---you came out a winner. Come again.") else: - print(f"Congratulations---you came out even, not bad for an amateur") + print("Congratulations---you came out even, not bad for an amateur") diff --git a/31_Depth_Charge/python/depth_charge.py b/31_Depth_Charge/python/depth_charge.py index 1d68c83b..c0180c79 100644 --- a/31_Depth_Charge/python/depth_charge.py +++ b/31_Depth_Charge/python/depth_charge.py @@ -73,7 +73,7 @@ def get_shot_input(): x, y, z = raw_guess.split() except ValueError: print("Please enter coordinates separated by spaces") - print(f"Example: 3 2 1") + print("Example: 3 2 1") continue try: x, y, z = (int(num) for num in [x, y, z]) diff --git a/35_Even_Wins/python/evenwins.py b/35_Even_Wins/python/evenwins.py index 77f986f6..97032239 100644 --- a/35_Even_Wins/python/evenwins.py +++ b/35_Even_Wins/python/evenwins.py @@ -19,8 +19,6 @@ # more structured style. # -import random - # global variables marbles_in_middle = -1 human_marbles = -1 diff --git a/38_Fur_Trader/python/furtrader.py b/38_Fur_Trader/python/furtrader.py index 5b0edc72..deeb3f67 100755 --- a/38_Fur_Trader/python/furtrader.py +++ b/38_Fur_Trader/python/furtrader.py @@ -249,7 +249,7 @@ if __name__ == "__main__": beaver_price = ( int((0.25 * random.random() + 1.00) * 100 + 0.5) / 100 ) # INT((.25*RND(1)+1.00)*10^2+.5)/10^2 - if fox_price == None: + if fox_price is None: # Original Bug? There is no Fox price generated for New York, it will use any previous "D1" price # So if there was no previous value, make one up fox_price = ( diff --git a/40_Gomoko/python/Gomoko.py b/40_Gomoko/python/Gomoko.py index 8715676f..294e9300 100644 --- a/40_Gomoko/python/Gomoko.py +++ b/40_Gomoko/python/Gomoko.py @@ -1,12 +1,12 @@ import random -from typing import List, Tuple +from typing import Any, List, Tuple def print_n_whitespaces(n: int) -> None: print(" " * n, end="") -def print_board(): +def print_board(A: List[List[Any]], n): """PRINT THE BOARD""" for i in range(n): print(" ", end="") @@ -128,7 +128,7 @@ def main(): and board[X - 1][Y - 1] == 0 ): board[X - 1][Y - 1] = 2 - print_board() + print_board(board, n) break else: if board[X - 1][Y - 1] != 0: @@ -140,11 +140,11 @@ def main(): and board[X - 1][Y - 1] == 0 ): board[X - 1][Y - 1] = 2 - print_board() + print_board(board, n) break else: board[X - 1][Y - 1] = 2 - print_board() + print_board(board, n) print() print("THANKS FOR THE GAME!!") repeat = input("PLAY AGAIN (1 FOR YES, 0 FOR NO)? ") diff --git a/45_Hello/python/hello.py b/45_Hello/python/hello.py index 82162ff1..a69cc33d 100644 --- a/45_Hello/python/hello.py +++ b/45_Hello/python/hello.py @@ -73,16 +73,16 @@ def solve_sex_problem(user_name): valid, too_much = prompt_too_much_or_too_little() if valid: if too_much: - print(f"YOU CALL THAT A PROBLEM?!! I SHOULD HAVE SUCH PROBLEMS!") + print("YOU CALL THAT A PROBLEM?!! I SHOULD HAVE SUCH PROBLEMS!") print(f"IF IT BOTHERS YOU, {user_name}, TAKE A COLD SHOWER.") else: print(f"WHY ARE YOU HERE IN SUFFERN, {user_name}? YOU SHOULD BE") - print(f"IN TOKYO OR NEW YORK OR AMSTERDAM OR SOMEPLACE WITH SOME") - print(f"REAL ACTION.") + print("IN TOKYO OR NEW YORK OR AMSTERDAM OR SOMEPLACE WITH SOME") + print("REAL ACTION.") return else: print(f"DON'T GET ALL SHOOK, {user_name}, JUST ANSWER THE QUESTION") - print(f"WITH 'TOO MUCH' OR 'TOO LITTLE'. WHICH IS IT?") + print("WITH 'TOO MUCH' OR 'TOO LITTLE'. WHICH IS IT?") def solve_money_problem(user_name): @@ -140,7 +140,7 @@ def ask_question_loop(user_name): def ask_for_fee(user_name): print() print(f"THAT WILL BE $5.00 FOR THE ADVICE, {user_name}.") - print(f"PLEASE LEAVE THE MONEY ON THE TERMINAL.") + print("PLEASE LEAVE THE MONEY ON THE TERMINAL.") time.sleep(4) print() print() diff --git a/70_Poetry/python/poetry.py b/70_Poetry/python/poetry.py index 490378ac..f27a202e 100644 --- a/70_Poetry/python/poetry.py +++ b/70_Poetry/python/poetry.py @@ -12,10 +12,10 @@ Ported by Dave LeCompte # state. This adaptation pulls things apart into phrases, but I have # left the variables as globals, which makes goes against decades of # wisdom that global state is bad. +import random PAGE_WIDTH = 64 -import random # globals u = 0 diff --git a/84_Super_Star_Trek/python/superstartrek.py b/84_Super_Star_Trek/python/superstartrek.py index bd927bcc..5888cc58 100644 --- a/84_Super_Star_Trek/python/superstartrek.py +++ b/84_Super_Star_Trek/python/superstartrek.py @@ -919,7 +919,7 @@ def end_game(won=False, quit=True, enterprise_killed=False): print(f"IT IS STARDATE {round(t, 1)}") print(f"THERE WERE {k9} KLINGON BATTLE CRUISERS LEFT AT") - print(f"THE END OF YOUR MISSION.\n\n") + print("THE END OF YOUR MISSION.\n\n") if b9 == 0: exit() diff --git a/86_Target/python/target.py b/86_Target/python/target.py index 68fd9521..055891b0 100644 --- a/86_Target/python/target.py +++ b/86_Target/python/target.py @@ -6,7 +6,6 @@ Weapon targeting simulation / 3d trigonometry practice Ported by Dave LeCompte """ -import collections import math import random @@ -129,9 +128,9 @@ def do_shot_loop(p1, x, y, z): print() print(" * * * HIT * * * TARGET IS NON FUNCTIONAL") print() - print(f"DISTANCE OF EXPLOSION FROM TARGET WAS {d:.4f} KILOMETERS") + print(f"DISTANCE OF EXPLOSION FROM TARGET WAS {distance:.4f} KILOMETERS") print() - print(f"MISSION ACCOMPLISHED IN {r} SHOTS.") + print(f"MISSION ACCOMPLISHED IN {shot_count} SHOTS.") return else: diff --git a/88_3-D_Tic-Tac-Toe/python/qubit.py b/88_3-D_Tic-Tac-Toe/python/qubit.py index f6a752b9..da5a6c59 100644 --- a/88_3-D_Tic-Tac-Toe/python/qubit.py +++ b/88_3-D_Tic-Tac-Toe/python/qubit.py @@ -205,13 +205,13 @@ class TicTacToe3D: return event(i) m = self.markAndMove(80, 88, 43) - if m != None: + if m is not None: return m self.clearStrategyMarks() m = self.markAndMove(16, 24, 11) - if m != None: + if m is not None: return m for k in range(18): @@ -223,7 +223,7 @@ class TicTacToe3D: for s in [1, 0]: for i in range(4 * k, 4 * k + 4): m = self.moveDiagonals(i, s) - if m != None: + if m is not None: return m self.clearStrategyMarks() diff --git a/89_Tic-Tac-Toe/python/tictactoe2.py b/89_Tic-Tac-Toe/python/tictactoe2.py index 4f0aae67..bd7ad9e1 100755 --- a/89_Tic-Tac-Toe/python/tictactoe2.py +++ b/89_Tic-Tac-Toe/python/tictactoe2.py @@ -117,13 +117,13 @@ def think(board, g, h, moves): if g == OccupiedBy.PLAYER: j = 3 * int((moves - 1) / 3) - if move == j + 1: + if move == j + 1: # noqa: This definitely is a bug! k = 1 - if move == j + 2: + if move == j + 2: # noqa: This definitely is a bug! k = 2 - if move == j + 3: + if move == j + 3: # noqa: This definitely is a bug! k = 3 - return subthink(g, h, j, k) + return subthink(g, h, j, k) # noqa: This definitely is a bug! def render_board(board, space_mapping):