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

Commit 33b8ff6

Browse files
committed
Fix code style issues with Black
1 parent 27f61a6 commit 33b8ff6

3 files changed

Lines changed: 35 additions & 18 deletions

File tree

projects/Guess Number/guess_num_v2.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
upper_limit = 10
99
secret_number = random.randint(lower_limit, upper_limit)
1010

11+
1112
# Function to check if the user's guess is correct
1213
def check_guess():
1314
user_guess = int(guess_entry.get())
@@ -18,10 +19,12 @@ def check_guess():
1819
else:
1920
result_label.config(text="Try a lower number.")
2021

22+
2123
# Function to exit the application
2224
def exit_game():
2325
root.destroy() # Close the Tkinter window and exit the application
2426

27+
2528
# Create the main application window
2629
root = tk.Tk()
2730
root.title("Number Guessing Game")
@@ -31,7 +34,9 @@ def exit_game():
3134
root.configure(bg="pink1")
3235

3336
# Create and place widgets using grid
34-
instructions_label = tk.Label(root, text=f"Guess a number between {lower_limit} and {upper_limit}:", bg="pink1")
37+
instructions_label = tk.Label(
38+
root, text=f"Guess a number between {lower_limit} and {upper_limit}:", bg="pink1"
39+
)
3540
instructions_label.grid(row=0, column=0, columnspan=2)
3641

3742
guess_entry = tk.Entry(root)

projects/Madlibs Generator/main.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,37 @@ def generate_madlib(choice, adjective, noun, verb, adverb):
22
stories = {
33
1: f"Once upon a time, there was a {adjective} {noun} who loved to {verb} {adverb}.",
44
2: f"In a land far away, a {adjective} {noun} decided to {verb} {adverb} every day.",
5-
3: f"{adjective.capitalize()} and {noun.capitalize()}, the perfect pair, went on a journey to {verb} {adverb}."
5+
3: f"{adjective.capitalize()} and {noun.capitalize()}, the perfect pair, went on a journey to {verb} {adverb}.",
66
}
7-
7+
88
return stories.get(choice, "Invalid choice!")
99

10+
1011
def main():
1112
print("Welcome to Mad Libs!")
12-
13+
1314
# Choose a Mad Lib template
1415
print("Choose a Mad Lib story:")
1516
print("1. Once upon a time")
1617
print("2. In a land far away")
1718
print("3. A perfect pair")
18-
19+
1920
choice = int(input("Enter the number of your choice (1-3): "))
20-
21+
2122
if choice not in [1, 2, 3]:
2223
print("Invalid choice. Please select a valid option.")
2324
return
24-
25+
2526
adjective = input("Enter an adjective: ")
2627
noun = input("Enter a noun: ")
2728
verb = input("Enter a verb: ")
2829
adverb = input("Enter an adverb: ")
29-
30+
3031
madlib = generate_madlib(choice, adjective, noun, verb, adverb)
31-
32+
3233
print("Your Mad Lib Story:")
3334
print(madlib)
3435

36+
3537
if __name__ == "__main__":
3638
main()

projects/Video-subtitle-generator/main.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ def transcribe_audio(path, output_filetype="srt", whisper_model="base"):
1111
if os.path.exists(output_filename):
1212
i = 1
1313
while os.path.exists(output_filename):
14-
output_filename = os.path.join("SrtFiles", f"{filename}({i}).{output_filetype}")
14+
output_filename = os.path.join(
15+
"SrtFiles", f"{filename}({i}).{output_filetype}"
16+
)
1517
i += 1
1618
if output_filetype == "srt":
1719
# open the output file in write mode
@@ -31,11 +33,11 @@ def transcribe_audio(path, output_filetype="srt", whisper_model="base"):
3133
with open(output_filename, "a", encoding="utf-8") as srtFile:
3234
srtFile.write(segment)
3335
return srtFile
34-
36+
3537
elif output_filetype == "json":
3638
with open(output_filename, "w", encoding="utf-8") as jsonFile:
37-
jsonFile.write("{\n \"captions\": [\n")
38-
model = whisper.load_model(whisper_model)
39+
jsonFile.write('{\n "captions": [\n')
40+
model = whisper.load_model(whisper_model)
3941
print("Whisper model loaded.")
4042
transcribe = model.transcribe(audio=path)
4143
segments = transcribe["segments"]
@@ -48,17 +50,17 @@ def transcribe_audio(path, output_filetype="srt", whisper_model="base"):
4850
duration_str = str(0) + str(duration) + ",000"
4951
text = segment["text"]
5052
segmentId = segment["id"] + 1
51-
segment = f"{{\t\n\"id\": {segmentId},\n\"start\": \"{startTime_str}\",\n\"end\": \"{endTime_str}\",\n\"duration\": \"{duration_str}\",\n\"text\": \"{text[1:] if text[0] == ' ' else text}\"\n}},\n"
53+
segment = f"{{\t\n\"id\": {segmentId},\n\"start\": \"{startTime_str}\",\n\"end\": \"{endTime_str}\",\n\"duration\": \"{duration_str}\",\n\"text\": \"{text[1:] if text[0] == ' ' else text}\"\n}},\n"
5254
with open(output_filename, "a", encoding="utf-8") as jsonFile:
5355
jsonFile.write(segment)
54-
# remove the last comma
56+
# remove the last comma
5557
with open(output_filename, "rb+") as jsonFile:
5658
jsonFile.seek(-2, os.SEEK_END)
5759
jsonFile.truncate()
5860
with open(output_filename, "a", encoding="utf-8") as jsonFile:
5961
jsonFile.write("\n]\n}")
6062
return jsonFile
61-
63+
6264
elif output_filetype == "txt":
6365
with open(output_filename, "w", encoding="utf-8") as txtFile:
6466
txtFile.write("")
@@ -82,15 +84,23 @@ def transcribe_audio(path, output_filetype="srt", whisper_model="base"):
8284
if not os.path.exists(output_dir):
8385
os.mkdir("SrtFiles")
8486
path = input("Please enter the path of the audio file:")
85-
output_filetype = int(input("Please enter the output file type (SRT is selected by default):\n1.SRT\n2.JSON\n3.TXT\n"))
87+
output_filetype = int(
88+
input(
89+
"Please enter the output file type (SRT is selected by default):\n1.SRT\n2.JSON\n3.TXT\n"
90+
)
91+
)
8692
if output_filetype == 1:
8793
output_filetype = "srt"
8894
elif output_filetype == 2:
8995
output_filetype = "json"
9096
elif output_filetype == 3:
9197
output_filetype = "txt"
9298

93-
whisper_model = int(input("Please enter the name of the whisper model you want to use (base is selected by default):\n1.Tiny\n2.Base\n3.Small\n4.Medium\n5.Large\n"))
99+
whisper_model = int(
100+
input(
101+
"Please enter the name of the whisper model you want to use (base is selected by default):\n1.Tiny\n2.Base\n3.Small\n4.Medium\n5.Large\n"
102+
)
103+
)
94104
if whisper_model == 1:
95105
whisper_model = "tiny"
96106
elif whisper_model == 2:

0 commit comments

Comments
 (0)