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

Commit b9cc415

Browse files
committed
Fix code style issues with Black
1 parent 156f2c6 commit b9cc415

3 files changed

Lines changed: 72 additions & 41 deletions

File tree

projects/Audiobook/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
pdf = None
77
stop_thread = False # Variable to signal stopping the playback
88

9+
910
def play(pdfReader):
1011
global pdf
1112
global stop_thread
@@ -21,11 +22,13 @@ def play(pdfReader):
2122

2223
speaker.stop()
2324

25+
2426
def stop_playback():
2527
global stop_thread
2628
input("Press Enter to stop playback...")
2729
stop_thread = True # Set the flag to stop playback
2830

31+
2932
file = input("Enter your PDF file name: ")
3033

3134
while True:
@@ -42,7 +45,7 @@ def stop_playback():
4245
playback_thread.start()
4346

4447
# Start a thread for stopping playback with keyboard input
45-
keyboard.add_hotkey('q', lambda: stop_playback())
48+
keyboard.add_hotkey("q", lambda: stop_playback())
4649
keyboard.wait() # Wait for the hotkey event
4750

4851
# Wait for the playback to finish

projects/Expense-Tracker/main.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sqlite3
22

33
# Connect to the database
4-
conn = sqlite3.connect('expenses.db')
4+
conn = sqlite3.connect("expenses.db")
55
cursor = conn.cursor()
66

77
# Define SQL statements
@@ -12,58 +12,63 @@
1212
update_expense_by_id_sql = "UPDATE expenses SET description=? WHERE id=?"
1313

1414
# Check if the database exists, create it if not
15-
if not conn.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='expenses';").fetchone():
15+
if not conn.execute(
16+
"SELECT name FROM sqlite_master WHERE type='table' AND name='expenses';"
17+
).fetchone():
1618
cursor.execute(create_table_sql)
1719
conn.commit()
1820

21+
1922
def add_expense():
2023
global cursor
21-
24+
2225
# Get input from user
2326
print("Enter date (YYYY-MM-DD): ")
24-
date = input().split()[0] + '-01'
27+
date = input().split()[0] + "-01"
2528
print("Enter description: ")
2629
description = input()
2730
print("Enter amount: ")
2831
amount = float(input())
29-
32+
3033
try:
3134
cursor.execute(insert_expense_sql, (date, description, amount))
3235
conn.commit()
3336
print("Expense added successfully.")
3437
except Exception as e:
3538
print("Error adding expense: {}".format(e))
36-
39+
40+
3741
def delete_expense():
3842
global cursor
39-
43+
4044
# Get ID from user
4145
print("Enter ID to delete: ")
4246
id = int(input())
43-
47+
4448
try:
4549
cursor.execute(delete_expense_by_id_sql, (id,))
4650
conn.commit()
4751
print("Expense deleted successfully.")
4852
except Exception as e:
4953
print("Error deleting expense: {}".format(e))
50-
54+
55+
5156
def update_expense():
5257
global cursor
53-
58+
5459
# Get ID and new description from user
5560
print("Enter ID to update: ")
5661
id = int(input())
5762
print("Enter new description: ")
5863
description = input()
59-
64+
6065
try:
6166
cursor.execute(update_expense_by_id_sql, (description, id))
6267
conn.commit()
6368
print("Expense updated successfully.")
6469
except Exception as e:
6570
print("Error updating expense: {}".format(e))
66-
71+
6772

6873
def view_expenses():
6974
# Fetch and display expenses
@@ -73,13 +78,17 @@ def view_expenses():
7378
else:
7479
print("Expenses:")
7580
for expense in expenses:
76-
print(f"ID: {expense[0]}, Date: {expense[1]}, Description: {expense[2]}, Amount: Rs: {expense[3]}")
81+
print(
82+
f"ID: {expense[0]}, Date: {expense[1]}, Description: {expense[2]}, Amount: Rs: {expense[3]}"
83+
)
84+
7785

7886
def total_expenses():
7987
# Calculate and display total expenses
8088
total = conn.execute("SELECT SUM(amount) FROM expenses;").fetchone()[0]
8189
print(f"Total expenses: {total}$")
8290

91+
8392
def main_menu():
8493
while True:
8594
print("\nExpense Tracker Menu:")
@@ -92,17 +101,17 @@ def main_menu():
92101

93102
choice = input("Enter your choice (1-6): ")
94103

95-
if choice == '1':
104+
if choice == "1":
96105
add_expense()
97-
elif choice == '2':
106+
elif choice == "2":
98107
view_expenses()
99-
elif choice == '3':
108+
elif choice == "3":
100109
total_expenses()
101-
elif choice == '4':
110+
elif choice == "4":
102111
delete_expense()
103-
elif choice == '5':
112+
elif choice == "5":
104113
update_expense()
105-
elif choice == '6':
114+
elif choice == "6":
106115
break
107116
else:
108117
print("Invalid choice. Please try again.")

projects/HandCricket/main.py

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,68 @@
11
import random
22
import time
33

4+
45
def main():
56
print("Welcome Hand Cricket")
67
print("You will be playing against the computer")
78
try:
89
overs = int(input("Enter the number of overs (1-10): "))
910
user_choice = input("Enter 1 to bat first, 2 to bowl first: ")
1011
difficulty = int(input("Select difficulty level (1-Easy, 2-Medium, 3-Hard): "))
11-
12+
1213
user_score, computer_score = play_game(overs, user_choice, difficulty)
13-
14+
1415
who_won(user_score, computer_score)
1516
except ValueError:
1617
print("Invalid input, exiting game")
1718

19+
1820
def play_game(overs, user_choice, difficulty=1):
1921
user_score = 0
2022
computer_score = 0
2123
user_wickets = 10
2224
computer_wickets = 10
23-
25+
2426
print("\nMatch Summary")
2527
print("=============")
2628
print(f"Overs: {overs}")
27-
29+
2830
for over in range(overs):
29-
print(f"\nOver {over + 1}, User: {user_wickets} wickets left, Computer: {computer_wickets} wickets left")
30-
31-
if user_choice == '1':
31+
print(
32+
f"\nOver {over + 1}, User: {user_wickets} wickets left, Computer: {computer_wickets} wickets left"
33+
)
34+
35+
if user_choice == "1":
3236
user_score, user_wickets = user_bat(user_score, user_wickets, over)
33-
37+
3438
if computer_wickets > 0:
35-
computer_score, computer_wickets = computer_bat(computer_score, computer_wickets, difficulty, over)
39+
computer_score, computer_wickets = computer_bat(
40+
computer_score, computer_wickets, difficulty, over
41+
)
3642
else:
3743
if computer_wickets > 0:
38-
computer_score, computer_wickets = computer_bat(computer_score, computer_wickets, difficulty, over)
39-
44+
computer_score, computer_wickets = computer_bat(
45+
computer_score, computer_wickets, difficulty, over
46+
)
47+
4048
user_score, user_wickets = user_bat(user_score, user_wickets, over)
41-
49+
4250
display_scoreboard(user_score, computer_score, over)
4351

4452
return user_score, computer_score
4553

54+
4655
def user_bat(user_score, user_wickets, over):
4756
print("You are batting")
4857
balls = 0
4958
while balls < 6 and user_wickets > 0:
50-
user_runs = int(input(f"Over {over + 1}, Ball {balls + 1}: Enter your shot (1-6): "))
59+
user_runs = int(
60+
input(f"Over {over + 1}, Ball {balls + 1}: Enter your shot (1-6): ")
61+
)
5162
computer_runs = random.randint(1, 6)
52-
63+
5364
print(f"You chose {user_runs}, Computer chose {computer_runs}")
54-
65+
5566
if user_runs == computer_runs:
5667
print("You are out!")
5768
user_wickets -= 1
@@ -61,9 +72,10 @@ def user_bat(user_score, user_wickets, over):
6172
user_score += user_runs
6273
print(f"Your score is {user_score}")
6374
balls += 1
64-
75+
6576
return user_score, user_wickets
6677

78+
6779
def computer_bat(computer_score, computer_wickets, difficulty=1, over=None):
6880
print("Computer is batting")
6981
balls = 0
@@ -74,11 +86,15 @@ def computer_bat(computer_score, computer_wickets, difficulty=1, over=None):
7486
computer_runs = random.randint(1, 5)
7587
else:
7688
computer_runs = random.randint(1, 6)
77-
78-
user_runs = int(input(f"Computer is batting. Over {over + 1}, Ball {balls + 1}: Enter your delivery (1-6): "))
79-
89+
90+
user_runs = int(
91+
input(
92+
f"Computer is batting. Over {over + 1}, Ball {balls + 1}: Enter your delivery (1-6): "
93+
)
94+
)
95+
8096
print(f"You chose {user_runs}, Computer chose {computer_runs}")
81-
97+
8298
if user_runs == computer_runs:
8399
print("Computer is out!")
84100
computer_wickets -= 1
@@ -88,16 +104,18 @@ def computer_bat(computer_score, computer_wickets, difficulty=1, over=None):
88104
computer_score += computer_runs
89105
print(f"Computer's score is {computer_score}")
90106
balls += 1
91-
107+
92108
return computer_score, computer_wickets
93109

110+
94111
def display_scoreboard(user_score, computer_score, over):
95112
print("\nScoreboard")
96113
print("==========")
97114
print(f"Over {over + 1}:")
98115
print(f"You: {user_score} runs")
99116
print(f"Computer: {computer_score} runs")
100117

118+
101119
def who_won(user_score, computer_score):
102120
print("\nMatch Result")
103121
print("============")
@@ -111,5 +129,6 @@ def who_won(user_score, computer_score):
111129
print("The match ended in a draw")
112130
print("Thank you for playing and have a good day :) ")
113131

132+
114133
if __name__ == "__main__":
115134
main()

0 commit comments

Comments
 (0)