Skip to content

Commit

Permalink
Follow Flake8 pep3101 and remove modulo formatting (TheAlgorithms#7339)
Browse files Browse the repository at this point in the history
* ci: Add ``flake8-pep3101`` plugin to ``pre-commit``

* refactor: Remove all modulo string formatting

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* refactor: Remove ``flake8-pep3101`` plugin from ``pre-commit``

* revert: Revert to modulo formatting

* refactor: Use f-string instead of `join`

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
CaedenPH and pre-commit-ci[bot] authored Oct 16, 2022
1 parent 7f6e0b6 commit f15cc2f
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 19 deletions.
9 changes: 3 additions & 6 deletions ciphers/elgamal_key_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,19 @@ def make_key_files(name: str, key_size: int) -> None:
if os.path.exists(f"{name}_pubkey.txt") or os.path.exists(f"{name}_privkey.txt"):
print("\nWARNING:")
print(
'"%s_pubkey.txt" or "%s_privkey.txt" already exists. \n'
f'"{name}_pubkey.txt" or "{name}_privkey.txt" already exists. \n'
"Use a different name or delete these files and re-run this program."
% (name, name)
)
sys.exit()

public_key, private_key = generate_key(key_size)
print(f"\nWriting public key to file {name}_pubkey.txt...")
with open(f"{name}_pubkey.txt", "w") as fo:
fo.write(
"%d,%d,%d,%d" % (public_key[0], public_key[1], public_key[2], public_key[3])
)
fo.write(f"{public_key[0]},{public_key[1]},{public_key[2]},{public_key[3]}")

print(f"Writing private key to file {name}_privkey.txt...")
with open(f"{name}_privkey.txt", "w") as fo:
fo.write("%d,%d" % (private_key[0], private_key[1]))
fo.write(f"{private_key[0]},{private_key[1]}")


def main() -> None:
Expand Down
3 changes: 1 addition & 2 deletions ciphers/rsa_key_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ def make_key_files(name: str, key_size: int) -> None:
if os.path.exists(f"{name}_pubkey.txt") or os.path.exists(f"{name}_privkey.txt"):
print("\nWARNING:")
print(
'"%s_pubkey.txt" or "%s_privkey.txt" already exists. \n'
f'"{name}_pubkey.txt" or "{name}_privkey.txt" already exists. \n'
"Use a different name or delete these files and re-run this program."
% (name, name)
)
sys.exit()

Expand Down
4 changes: 2 additions & 2 deletions dynamic_programming/edit_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def min_distance_bottom_up(word1: str, word2: str) -> int:
S2 = input("Enter the second string: ").strip()

print()
print("The minimum Edit Distance is: %d" % (solver.solve(S1, S2)))
print("The minimum Edit Distance is: %d" % (min_distance_bottom_up(S1, S2)))
print(f"The minimum Edit Distance is: {solver.solve(S1, S2)}")
print(f"The minimum Edit Distance is: {min_distance_bottom_up(S1, S2)}")
print()
print("*************** End of Testing Edit Distance DP Algorithm ***************")
4 changes: 2 additions & 2 deletions genetic_algorithm/basic_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def mutate(child: str) -> str:
" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklm"
"nopqrstuvwxyz.,;!?+-*#@^'èéòà€ù=)(&%$£/\\"
)
generation, population, target = basic(target_str, genes_list)
print(
"\nGeneration: %s\nTotal Population: %s\nTarget: %s"
% basic(target_str, genes_list)
f"\nGeneration: {generation}\nTotal Population: {population}\nTarget: {target}"
)
2 changes: 1 addition & 1 deletion graphs/minimum_spanning_tree_boruvka.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __str__(self):
for tail in self.adjacency:
for head in self.adjacency[tail]:
weight = self.adjacency[head][tail]
string += "%d -> %d == %d\n" % (head, tail, weight)
string += f"{head} -> {tail} == {weight}\n"
return string.rstrip("\n")

def get_edges(self):
Expand Down
2 changes: 1 addition & 1 deletion machine_learning/linear_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def run_linear_regression(data_x, data_y):
for i in range(0, iterations):
theta = run_steep_gradient_descent(data_x, data_y, len_data, alpha, theta)
error = sum_of_square_error(data_x, data_y, len_data, theta)
print("At Iteration %d - Error is %.5f " % (i + 1, error))
print(f"At Iteration {i + 1} - Error is {error:.5f}")

return theta

Expand Down
6 changes: 3 additions & 3 deletions matrix/sherman_morrison.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ def __str__(self) -> str:
"""

# Prefix
s = "Matrix consist of %d rows and %d columns\n" % (self.row, self.column)
s = f"Matrix consist of {self.row} rows and {self.column} columns\n"

# Make string identifier
max_element_length = 0
for row_vector in self.array:
for obj in row_vector:
max_element_length = max(max_element_length, len(str(obj)))
string_format_identifier = "%%%ds" % (max_element_length,)
string_format_identifier = f"%{max_element_length}s"

# Make string and return
def single_line(row_vector: list[float]) -> str:
Expand Down Expand Up @@ -252,7 +252,7 @@ def test1() -> None:
v[0, 0], v[1, 0], v[2, 0] = 4, -2, 5
print(f"u is {u}")
print(f"v is {v}")
print("uv^T is %s" % (u * v.transpose()))
print(f"uv^T is {u * v.transpose()}")
# Sherman Morrison
print(f"(a + uv^T)^(-1) is {ainv.sherman_morrison(u, v)}")

Expand Down
2 changes: 1 addition & 1 deletion neural_network/back_propagation_neural_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def build(self):

def summary(self):
for i, layer in enumerate(self.layers[:]):
print("------- layer %d -------" % i)
print(f"------- layer {i} -------")
print("weight.shape ", np.shape(layer.weight))
print("bias.shape ", np.shape(layer.bias))

Expand Down
2 changes: 1 addition & 1 deletion neural_network/convolution_neural_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def train(
mse = 10000
while rp < n_repeat and mse >= error_accuracy:
error_count = 0
print("-------------Learning Time %d--------------" % rp)
print(f"-------------Learning Time {rp}--------------")
for p in range(len(datas_train)):
# print('------------Learning Image: %d--------------'%p)
data_train = np.asmatrix(datas_train[p])
Expand Down

0 comments on commit f15cc2f

Please sign in to comment.