Skip to content

Follow Flake8 pep3101 and remove modulo formatting #7339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 16, 2022
Merged
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
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