Skip to content

Commit 4929a7f

Browse files
committed
fix error
1 parent 957533b commit 4929a7f

File tree

10 files changed

+67
-46
lines changed

10 files changed

+67
-46
lines changed

BoardGame-CLI/uno.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ def main() -> None:
158158
while not canPlay(
159159
currentColour, cardVal, [players[playerTurn][cardChosen - 1]]
160160
):
161-
cardChosen = int(input("Not a valid card. Which card do you want to play?"))
161+
cardChosen = int(
162+
input("Not a valid card. Which card do you want to play?")
163+
)
162164
print("You played {}".format(players[playerTurn][cardChosen - 1]))
163165
discards.append(players[playerTurn].pop(cardChosen - 1))
164166

@@ -181,7 +183,9 @@ def main() -> None:
181183
newColour = int(input("What colour would you like to choose? "))
182184
while newColour < 1 or newColour > 4:
183185
newColour = int(
184-
input("Invalid option. What colour would you like to choose")
186+
input(
187+
"Invalid option. What colour would you like to choose"
188+
)
185189
)
186190
currentColour = colours[newColour - 1]
187191
if cardVal == "Reverse":

Industrial_developed_hangman/tests/test_hangman/test_main.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import os
2-
from pathlib import Path
31
from typing import Callable, List
42

53
import pytest
@@ -8,7 +6,6 @@
86
from src.hangman.main import (
97
MainProcess,
108
Source,
11-
parse_word_from_local,
129
parse_word_from_site,
1310
)
1411

Tic-Tac-Toe Games/tic-tac-toe1.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ def print_board(board: Board) -> None:
2828
def check_winner(board: Board, player: str) -> bool:
2929
"""Return True if `player` has won."""
3030
for i in range(3):
31-
if all(board[i][j] == player for j in range(3)) or \
32-
all(board[j][i] == player for j in range(3)):
31+
if all(board[i][j] == player for j in range(3)) or all(
32+
board[j][i] == player for j in range(3)
33+
):
3334
return True
34-
if all(board[i][i] == player for i in range(3)) or \
35-
all(board[i][2 - i] == player for i in range(3)):
35+
if all(board[i][i] == player for i in range(3)) or all(
36+
board[i][2 - i] == player for i in range(3)
37+
):
3638
return True
3739
return False
3840

@@ -86,5 +88,6 @@ def main() -> None:
8688

8789
if __name__ == "__main__":
8890
import doctest
91+
8992
doctest.testmod()
9093
main()

Tic-Tac-Toe Games/tic-tac-toe3.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
def check_winner(board: Board, player: str) -> bool:
2222
"""Check if `player` has a winning line on `board`."""
2323
for i in range(3):
24-
if all(board[i][j] == player for j in range(3)) or \
25-
all(board[j][i] == player for j in range(3)):
24+
if all(board[i][j] == player for j in range(3)) or all(
25+
board[j][i] == player for j in range(3)
26+
):
2627
return True
27-
if all(board[i][i] == player for i in range(3)) or \
28-
all(board[i][2 - i] == player for i in range(3)):
28+
if all(board[i][i] == player for i in range(3)) or all(
29+
board[i][2 - i] == player for i in range(3)
30+
):
2931
return True
3032
return False
3133

@@ -116,22 +118,26 @@ def ai_move() -> None:
116118
# --- Initialize GUI ---
117119
root = ctk.CTk()
118120
root.title("Tic-Tac-Toe")
119-
board: Board = [[" "]*3 for _ in range(3)]
121+
board: Board = [[" "] * 3 for _ in range(3)]
120122
buttons: List[List[ctk.CTkButton]] = []
121123

122124
for i in range(3):
123125
row_buttons: List[ctk.CTkButton] = []
124126
for j in range(3):
125127
btn = ctk.CTkButton(
126-
root, text=" ", font=("normal", 30),
127-
width=100, height=100,
128-
command=lambda r=i, c=j: make_move(r, c)
128+
root,
129+
text=" ",
130+
font=("normal", 30),
131+
width=100,
132+
height=100,
133+
command=lambda r=i, c=j: make_move(r, c),
129134
)
130135
btn.grid(row=i, column=j, padx=2, pady=2)
131136
row_buttons.append(btn)
132137
buttons.append(row_buttons)
133138

134139
if __name__ == "__main__":
135140
import doctest
141+
136142
doctest.testmod()
137143
root.mainloop()

Tic-Tac-Toe Games/tic-tac-toe6.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,14 @@ def check_win(player_pos: Dict[str, List[int]], cur_player: str) -> bool:
6262
False
6363
"""
6464
soln = [
65-
[1, 2, 3], [4, 5, 6], [7, 8, 9], # Rows
66-
[1, 4, 7], [2, 5, 8], [3, 6, 9], # Columns
67-
[1, 5, 9], [3, 5, 7] # Diagonals
65+
[1, 2, 3],
66+
[4, 5, 6],
67+
[7, 8, 9], # Rows
68+
[1, 4, 7],
69+
[2, 5, 8],
70+
[3, 6, 9], # Columns
71+
[1, 5, 9],
72+
[3, 5, 7], # Diagonals
6873
]
6974
return any(all(pos in player_pos[cur_player] for pos in combo) for combo in soln)
7075

Timetable_Operations.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,6 @@ def calculate() -> None:
6767

6868
if __name__ == "__main__":
6969
import doctest
70+
7071
doctest.testmod()
7172
root.mainloop()

simple_calculator.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
4.0
1515
"""
1616

17+
1718
def add(x: float, y: float) -> float:
1819
"""Return the sum of x and y."""
1920
return x + y
@@ -41,17 +42,17 @@ def calculator() -> None:
4142

4243
while True:
4344
choice: str = input("Enter choice (1/2/3/4): ").strip()
44-
if choice in ('1', '2', '3', '4'):
45+
if choice in ("1", "2", "3", "4"):
4546
num1: float = float(input("Enter first number: "))
4647
num2: float = float(input("Enter second number: "))
4748

48-
if choice == '1':
49+
if choice == "1":
4950
print(f"{num1} + {num2} = {add(num1, num2)}")
50-
elif choice == '2':
51+
elif choice == "2":
5152
print(f"{num1} - {num2} = {subtract(num1, num2)}")
52-
elif choice == '3':
53+
elif choice == "3":
5354
print(f"{num1} * {num2} = {multiply(num1, num2)}")
54-
elif choice == '4':
55+
elif choice == "4":
5556
print(f"{num1} / {num2} = {divide(num1, num2)}")
5657
break
5758
else:
@@ -60,5 +61,6 @@ def calculator() -> None:
6061

6162
if __name__ == "__main__":
6263
import doctest
64+
6365
doctest.testmod()
6466
calculator()

smart_file_organizer.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ def organize_files(base_path: str) -> None:
6868
Args:
6969
base_path: Path of the directory to organize.
7070
"""
71-
files = [f for f in os.listdir(base_path) if os.path.isfile(os.path.join(base_path, f))]
71+
files = [
72+
f for f in os.listdir(base_path) if os.path.isfile(os.path.join(base_path, f))
73+
]
7274
if not files:
7375
print(f"[{datetime.now().strftime('%H:%M:%S')}] No files found in {base_path}")
7476
return
@@ -82,26 +84,26 @@ def organize_files(base_path: str) -> None:
8284

8385
try:
8486
shutil.move(source, os.path.join(target_folder, file_name))
85-
print(f"[{datetime.now().strftime('%H:%M:%S')}] Moved: {file_name} -> {category}/")
87+
print(
88+
f"[{datetime.now().strftime('%H:%M:%S')}] Moved: {file_name} -> {category}/"
89+
)
8690
except Exception as e:
87-
print(f"[{datetime.now().strftime('%H:%M:%S')}] Error moving {file_name}: {e}")
91+
print(
92+
f"[{datetime.now().strftime('%H:%M:%S')}] Error moving {file_name}: {e}"
93+
)
8894

8995

9096
def main() -> None:
9197
"""Parse command-line arguments and execute the file organizer."""
9298
parser = argparse.ArgumentParser(
9399
description="Organize files in a directory into categorized subfolders."
94100
)
95-
parser.add_argument(
96-
"--path",
97-
required=True,
98-
help="Directory path to organize."
99-
)
101+
parser.add_argument("--path", required=True, help="Directory path to organize.")
100102
parser.add_argument(
101103
"--interval",
102104
type=int,
103105
default=0,
104-
help="Interval (in minutes) to repeat automatically (0 = run once)."
106+
help="Interval (in minutes) to repeat automatically (0 = run once).",
105107
)
106108
args = parser.parse_args()
107109

time_delta.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Time Delta Calculator
33
4-
This module provides functionality to calculate the absolute difference
4+
This module provides functionality to calculate the absolute difference
55
in seconds between two timestamps in the format: Day dd Mon yyyy hh:mm:ss +xxxx
66
"""
77
# -----------------------------------------------------------------------------
@@ -31,18 +31,17 @@
3131
# 88200
3232
# ------------------------------------------------------------------------------
3333

34-
3534
import datetime
3635
from typing import List, Tuple
3736

3837

3938
def parse_timestamp(timestamp: str) -> datetime.datetime:
4039
"""
4140
Parse a timestamp string into a datetime object.
42-
41+
4342
Args:
4443
timestamp: String in the format "Day dd Mon yyyy hh:mm:ss +xxxx"
45-
44+
4645
Returns:
4746
A datetime object with timezone information
4847
"""
@@ -54,18 +53,18 @@ def parse_timestamp(timestamp: str) -> datetime.datetime:
5453
def calculate_time_delta(t1: str, t2: str) -> int:
5554
"""
5655
Calculate the absolute time difference between two timestamps in seconds.
57-
56+
5857
Args:
5958
t1: First timestamp string
6059
t2: Second timestamp string
61-
60+
6261
Returns:
6362
Absolute time difference in seconds as an integer
6463
"""
6564
# Parse both timestamps
6665
dt1 = parse_timestamp(t1)
6766
dt2 = parse_timestamp(t2)
68-
67+
6968
# Calculate absolute difference and convert to seconds
7069
time_difference = abs(dt1 - dt2)
7170
return int(time_difference.total_seconds())
@@ -74,7 +73,7 @@ def calculate_time_delta(t1: str, t2: str) -> int:
7473
def read_test_cases() -> Tuple[int, List[Tuple[str, str]]]:
7574
"""
7675
Read test cases from standard input.
77-
76+
7877
Returns:
7978
A tuple containing:
8079
- Number of test cases
@@ -83,12 +82,12 @@ def read_test_cases() -> Tuple[int, List[Tuple[str, str]]]:
8382
try:
8483
num_test_cases = int(input().strip())
8584
test_cases = []
86-
85+
8786
for _ in range(num_test_cases):
8887
timestamp1 = input().strip()
8988
timestamp2 = input().strip()
9089
test_cases.append((timestamp1, timestamp2))
91-
90+
9291
return num_test_cases, test_cases
9392
except ValueError as e:
9493
raise ValueError("Invalid input format") from e
@@ -100,11 +99,11 @@ def main() -> None:
10099
"""
101100
try:
102101
num_test_cases, test_cases = read_test_cases()
103-
102+
104103
for t1, t2 in test_cases:
105104
result = calculate_time_delta(t1, t2)
106105
print(result)
107-
106+
108107
except ValueError as e:
109108
print(f"Error: {e}")
110109
except Exception as e:

to check leap year.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
False
1616
"""
1717

18+
1819
def is_leap_year(year: int) -> bool:
1920
"""
2021
Return True if year is a leap year, False otherwise.
@@ -29,6 +30,7 @@ def is_leap_year(year: int) -> bool:
2930

3031
if __name__ == "__main__":
3132
import doctest
33+
3234
doctest.testmod()
3335

3436
year_input = input("Enter a year: ").strip()

0 commit comments

Comments
 (0)