Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 5bd099a

Browse files
committed
Fix code style issues with Black
1 parent 8006675 commit 5bd099a

44 files changed

Lines changed: 2540 additions & 1311 deletions

File tree

Some content is hidden

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

projects/API Based Weather Report/API Based Weather Report.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,35 @@ def write_to_file(location, weather_data):
3838

3939
# Writing temperature information to the file
4040
if "main" in weather_data and "temp" in weather_data["main"]:
41-
f.write("\tCurrent temperature is : {:.2f} °C\n".format(weather_data["main"]["temp"] - 273.15))
41+
f.write(
42+
"\tCurrent temperature is : {:.2f} °C\n".format(
43+
weather_data["main"]["temp"] - 273.15
44+
)
45+
)
4246

4347
# Writing weather description information to the file
4448
if "weather" in weather_data and weather_data["weather"]:
45-
f.write("\tCurrent weather desc : " + weather_data["weather"][0]["description"] + "\n")
49+
f.write(
50+
"\tCurrent weather desc : "
51+
+ weather_data["weather"][0]["description"]
52+
+ "\n"
53+
)
4654

4755
# Writing humidity information to the file
4856
if "main" in weather_data and "humidity" in weather_data["main"]:
49-
f.write("\tCurrent Humidity : {} %\n".format(weather_data["main"]["humidity"]))
57+
f.write(
58+
"\tCurrent Humidity : {} %\n".format(
59+
weather_data["main"]["humidity"]
60+
)
61+
)
5062

5163
# Writing wind speed information to the file
5264
if "wind" in weather_data and "speed" in weather_data["wind"]:
53-
f.write("\tCurrent wind speed : {} km/h \n".format(weather_data["wind"]["speed"]))
65+
f.write(
66+
"\tCurrent wind speed : {} km/h \n".format(
67+
weather_data["wind"]["speed"]
68+
)
69+
)
5470

5571
# Printing confirmation message after writing to file
5672
print("Weather information written to weatherinfo.txt")
@@ -65,7 +81,9 @@ def main():
6581
# Printing welcome messages and instructions
6682
print("Welcome to the Weather Information App!")
6783
print("You need an API key to access weather data from OpenWeatherMap.")
68-
print("You can obtain your API key by signing up at https://home.openweathermap.org/users/sign_up")
84+
print(
85+
"You can obtain your API key by signing up at https://home.openweathermap.org/users/sign_up"
86+
)
6987

7088
# Prompting the user to input API key and city name
7189
api_key = input("Please enter your OpenWeatherMap API key: ")
@@ -80,7 +98,11 @@ def main():
8098
write_to_file(location, weather_data)
8199

82100
# Printing weather information to console
83-
print("Current temperature is: {:.2f} °C".format(weather_data["main"]["temp"] - 273.15))
101+
print(
102+
"Current temperature is: {:.2f} °C".format(
103+
weather_data["main"]["temp"] - 273.15
104+
)
105+
)
84106
print("Current weather desc : " + weather_data["weather"][0]["description"])
85107
print("Current Humidity :", weather_data["main"]["humidity"], "%")
86108
print("Current wind speed :", weather_data["wind"]["speed"], "kmph")

projects/Adjactive_compartive_superlative/adjCS.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import re
44
import json
55

6-
nltk.download('wordnet', quiet=True)
6+
nltk.download("wordnet", quiet=True)
77

88
# Load irregular adjectives from a JSON file
9-
with open('irregular_adjectives.json', 'r') as f:
9+
with open("irregular_adjectives.json", "r") as f:
1010
IRREGULAR_ADJECTIVES = json.load(f)
1111

1212

@@ -17,8 +17,7 @@ def get_comp_sup(adjs):
1717
synsets = wordnet.synsets(adj, pos=wordnet.ADJ)
1818
if synsets:
1919
syn = synsets[0]
20-
comp_forms = [lemma.name().replace('_', ' ')
21-
for lemma in syn.lemmas()]
20+
comp_forms = [lemma.name().replace("_", " ") for lemma in syn.lemmas()]
2221
if len(comp_forms) >= 2:
2322
comp_form = comp_forms[1]
2423
else:
@@ -53,7 +52,7 @@ def get_superlative_form(adj):
5352

5453

5554
def main():
56-
adjs = input("Enter a list of adjectives (comma-separated): ").split(',')
55+
adjs = input("Enter a list of adjectives (comma-separated): ").split(",")
5756
adjs = [adj.strip() for adj in adjs]
5857

5958
comp_sup = get_comp_sup(adjs)

projects/Advisor/advisor.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ def advice():
1212
advice_text.set(res["slip"]["advice"])
1313
except requests.exceptions.RequestException:
1414
messagebox.showerror(
15-
"Error", "Failed to fetch advice. Please check your internet connection.")
15+
"Error", "Failed to fetch advice. Please check your internet connection."
16+
)
1617

1718

1819
# Create the main window
@@ -21,8 +22,9 @@ def advice():
2122

2223
# Create and configure widgets
2324
advice_text = tk.StringVar()
24-
advice_label = tk.Label(root, textvariable=advice_text,
25-
wraplength=400, font=("Arial", 14))
25+
advice_label = tk.Label(
26+
root, textvariable=advice_text, wraplength=400, font=("Arial", 14)
27+
)
2628
get_advice_button = tk.Button(root, text="Get Advice", command=advice)
2729

2830
# Pack widgets
@@ -33,4 +35,4 @@ def advice():
3335
advice()
3436

3537
# Run the main event loop
36-
root.mainloop()
38+
root.mainloop()
Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import tkinter as tk
22
from math import sin, cos, pi
33

4+
45
def update_clock():
56
current_time = time_var.get()
67
seconds = current_time % 60
@@ -12,39 +13,40 @@ def update_clock():
1213
minutes_angle = 90 - minutes * 6 - seconds * 0.1
1314
hours_angle = 90 - (hours * 30 + minutes * 0.5)
1415

15-
canvas.delete("all") #Deletes all previous drawings
16+
canvas.delete("all") # Deletes all previous drawings
1617

17-
canvas.create_oval(50, 50, 250, 250) #To draw clock face
18+
canvas.create_oval(50, 50, 250, 250) # To draw clock face
1819

19-
for i in range(1, 13): # Drawing clock numbers
20-
angle = 90 - i * 30 #Calculation of the angle for each number
20+
for i in range(1, 13): # Drawing clock numbers
21+
angle = 90 - i * 30 # Calculation of the angle for each number
2122
x = 150 + 85 * cos(angle * (pi / 180))
2223
y = 150 - 85 * sin(angle * (pi / 180))
2324
canvas.create_text(x, y, text=str(i), font=("Arial", 12, "bold"))
2425

25-
draw_hand(150, 150, seconds_angle, 80, 1)
26-
draw_hand(150, 150, minutes_angle, 70, 2)
27-
draw_hand(150, 150, hours_angle, 50, 4)
26+
draw_hand(150, 150, seconds_angle, 80, 1)
27+
draw_hand(150, 150, minutes_angle, 70, 2)
28+
draw_hand(150, 150, hours_angle, 50, 4)
29+
30+
time_var.set(current_time + 1) # Updating the time
31+
32+
root.after(1000, update_clock) # Updating the clock every 1000ms (1 second)
2833

29-
time_var.set(current_time + 1) # Updating the time
30-
31-
root.after(1000, update_clock) # Updating the clock every 1000ms (1 second)
3234

3335
def draw_hand(x, y, angle, length, width):
3436
radian_angle = angle * (pi / 180)
3537
end_x = x + length * cos(radian_angle)
36-
end_y = y - length * sin(radian_angle)
38+
end_y = y - length * sin(radian_angle)
3739
canvas.create_line(x, y, end_x, end_y, width=width)
3840

39-
root = tk.Tk() # Creating the main window
41+
42+
root = tk.Tk() # Creating the main window
4043
root.title("Analog Clock")
4144

4245
canvas = tk.Canvas(root, width=350, height=350)
4346
canvas.pack()
4447

4548
time_var = tk.IntVar()
46-
time_var.set(10 * 3600)
47-
48-
update_clock() # Starting the clock update function
49-
root.mainloop() # Running the Tkinter main loop
49+
time_var.set(10 * 3600)
5050

51+
update_clock() # Starting the clock update function
52+
root.mainloop() # Running the Tkinter main loop

projects/BMI_calculator/BMI calculator.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import tabulate
22
import csv
33

4+
45
def reference_chart():
56
"""
67
This is a function used to tabulate the data
78
of the bmi scale for the user, this requries a csv file 'bmi.csv' and two libraries "csv" and "tabulate".
89
It won't take any arguments and won't return anything
910
"""
10-
list2=[]
11-
with open('bmi.csv') as file1:
12-
list1=csv.reader(file1)
11+
list2 = []
12+
with open("bmi.csv") as file1:
13+
list1 = csv.reader(file1)
1314
for line in list1:
1415
list2.append(line)
1516
print("Here You can take the reference chart \n")
16-
print(tabulate.tabulate(list2[1:],headers=list2[0],tablefmt='fancy_grid'))
17+
print(tabulate.tabulate(list2[1:], headers=list2[0], tablefmt="fancy_grid"))
1718

1819

1920
def calculate_bmi(height, weight):

projects/Battleship/battleship_v2/board.py

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
@dataclass
99
class BoardStatesPlayerPOV:
1010
"""Cell's State Labels from Player's Point-of-View."""
11+
1112
missed: str = "M"
1213
hit: str = "H"
1314
ship: str = "S"
@@ -17,6 +18,7 @@ class BoardStatesPlayerPOV:
1718
@dataclass
1819
class BoardStatesEnemyPOV:
1920
"""Cell's State Labels from Enemy's Point-of-View."""
21+
2022
hit: str = "X"
2123
missed: str = "O"
2224
no_move: str = "-"
@@ -25,9 +27,7 @@ class BoardStatesEnemyPOV:
2527
class Board:
2628
"""Represents the Battleship Board."""
2729

28-
def __init__(self,
29-
board_size: int,
30-
empty_label=" "):
30+
def __init__(self, board_size: int, empty_label=" "):
3131
"""
3232
Initializes the Board object.
3333
@@ -40,12 +40,17 @@ def __init__(self,
4040
"""
4141

4242
if board_size < 5 or board_size > 15:
43-
raise BoardException("Invalid given board size. Board size must be 5 to 15.")
43+
raise BoardException(
44+
"Invalid given board size. Board size must be 5 to 15."
45+
)
4446

4547
self.board_size = board_size
4648
self._empty_label = empty_label
4749

48-
self._board = [[self._empty_label for _ in range(self.board_size)] for _ in range(self.board_size)]
50+
self._board = [
51+
[self._empty_label for _ in range(self.board_size)]
52+
for _ in range(self.board_size)
53+
]
4954

5055
# Instantiate Labels for Player and Enemy POVs
5156
self._player_pov_labels = BoardStatesPlayerPOV()
@@ -55,10 +60,7 @@ def __init__(self,
5560

5661
# Keep track of all enemy actions/moves for "Missed" and "No Move".
5762
# Hit can be obtained from `hit_cells` property.
58-
self._enemy_moves = {
59-
"hit": [],
60-
"missed": []
61-
}
63+
self._enemy_moves = {"hit": [], "missed": []}
6264

6365
@property
6466
def num_of_ships(self):
@@ -93,9 +95,14 @@ def is_player_lost(self) -> bool:
9395
@property
9496
def valid_moves(self) -> List[Tuple[int, int]]:
9597
"""Returns a list of available valid moves."""
96-
all_cells_generator = ((i, j) for i in range(self.board_size) for j in range(self.board_size))
97-
return [cell for cell in all_cells_generator if
98-
cell not in self._enemy_moves["hit"] + self._enemy_moves["missed"]]
98+
all_cells_generator = (
99+
(i, j) for i in range(self.board_size) for j in range(self.board_size)
100+
)
101+
return [
102+
cell
103+
for cell in all_cells_generator
104+
if cell not in self._enemy_moves["hit"] + self._enemy_moves["missed"]
105+
]
99106

100107
def generate_valid_moves(self) -> Generator[Tuple[int, int], None, None]:
101108
"""Yields all the available valid moves."""
@@ -117,11 +124,11 @@ def get_board_for_player(self) -> List[List[str]]:
117124
board[row][col] = self._player_pov_labels.ship
118125

119126
# Fill with Hit
120-
for (row, col) in self._enemy_moves["hit"]:
127+
for row, col in self._enemy_moves["hit"]:
121128
board[row][col] = self._player_pov_labels.hit
122129

123130
# Fill with Missed
124-
for (row, col) in self._enemy_moves["missed"]:
131+
for row, col in self._enemy_moves["missed"]:
125132
board[row][col] = self._player_pov_labels.missed
126133

127134
# Fill with Unoccupied
@@ -155,7 +162,10 @@ def get_board_for_enemy(self) -> List[List[str]]:
155162

156163
def _create_empty_board(self) -> List[List[str]]:
157164
"""Creates an empty board."""
158-
return [[self._empty_label for _ in range(self.board_size)] for _ in range(self.board_size)]
165+
return [
166+
[self._empty_label for _ in range(self.board_size)]
167+
for _ in range(self.board_size)
168+
]
159169

160170
@staticmethod
161171
def print_board(board: List[List[str]]) -> None:
@@ -225,8 +235,13 @@ def enemy_move(self, row: int, col: int) -> None:
225235

226236
# Check if the coordinate is already a hit or missed.
227237
board = self.get_board_for_enemy()
228-
if board[row][col] in [self._enemy_pov_labels.hit, self._enemy_pov_labels.missed]:
229-
raise BoardException(f"The given coordinate ({row}, {col}) already has {board[row][col]}.")
238+
if board[row][col] in [
239+
self._enemy_pov_labels.hit,
240+
self._enemy_pov_labels.missed,
241+
]:
242+
raise BoardException(
243+
f"The given coordinate ({row}, {col}) already has {board[row][col]}."
244+
)
230245

231246
ship: None | Ship = self.which_ship(row, col)
232247

0 commit comments

Comments
 (0)