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

Commit 1ede9ae

Browse files
committed
Fix code style issues with Black
1 parent f933ada commit 1ede9ae

2 files changed

Lines changed: 30 additions & 10 deletions

File tree

projects/Game of Cricket/main.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import random
22

3+
34
def get_user_choice():
45
while True:
56
try:
@@ -11,6 +12,7 @@ def get_user_choice():
1112
except ValueError:
1213
print("Invalid input. Please enter a number between 1 and 6.")
1314

15+
1416
def play_innings(player, overs, max_wickets):
1517
runs = 0
1618
wickets = 0
@@ -35,7 +37,9 @@ def play_innings(player, overs, max_wickets):
3537
if balls % 6 == 0:
3638
over_number = balls // 6
3739
print(f"End of Over {over_number}")
38-
print(f"Over {over_number} Summary: {player} scored {runs} runs with {wickets} wickets.")
40+
print(
41+
f"Over {over_number} Summary: {player} scored {runs} runs with {wickets} wickets."
42+
)
3943

4044
print(f"Total Score: {runs}/{wickets}")
4145
print(f"Balls remaining: {overs * 6 - balls}")
@@ -52,16 +56,23 @@ def play_innings(player, overs, max_wickets):
5256

5357
return runs, wickets
5458

59+
5560
print("~ Welcome to the Game of Cricket ~")
5661

5762
print("\nInstructions:")
5863
print("1. You have to select any number from 1 to 6.")
5964
print("2. The computer will also select a number.")
60-
print("3. While batting, if your number and computer's number are different, you'll add to your runs.")
65+
print(
66+
"3. While batting, if your number and computer's number are different, you'll add to your runs."
67+
)
6168
print(" If they are the same, you'll lose a wicket.")
62-
print("4. While bowling, if your number and computer's number are different, the computer adds to its runs.")
69+
print(
70+
"4. While bowling, if your number and computer's number are different, the computer adds to its runs."
71+
)
6372
print(" If they are the same, the computer loses a wicket.")
64-
print("5. Each player will get 2 wickets and 2 overs (12 balls) for batting and bowling.")
73+
print(
74+
"5. Each player will get 2 wickets and 2 overs (12 balls) for batting and bowling."
75+
)
6576
print("6. The innings will end after either three wickets fall or the overs end.")
6677
print("7. The player with the maximum runs wins.")
6778

@@ -81,7 +92,9 @@ def play_innings(player, overs, max_wickets):
8192
computer_choice = random.choice(["bat", "bowl"])
8293
user_choice = "bowl" if computer_choice == "bat" else "bat"
8394

84-
print(f"{toss_winner} chose to {user_choice} and the computer chose to {computer_choice}")
95+
print(
96+
f"{toss_winner} chose to {user_choice} and the computer chose to {computer_choice}"
97+
)
8598

8699
user_runs, user_wickets = play_innings("You", 2, 2)
87100
computer_runs, computer_wickets = play_innings("Computer", 2, 2)
@@ -93,6 +106,8 @@ def play_innings(player, overs, max_wickets):
93106
if user_runs > computer_runs:
94107
print(f"Congratulations! You won the Match by {user_runs - computer_runs} runs.")
95108
elif user_runs < computer_runs:
96-
print(f"Better luck next time! The Computer won the Match by {computer_runs - user_runs} runs.")
109+
print(
110+
f"Better luck next time! The Computer won the Match by {computer_runs - user_runs} runs."
111+
)
97112
else:
98113
print("The Match is a Tie. No one Wins.")

projects/Online Trivia/main.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
from time import sleep
33
import html
44

5-
def fetch_quiz_data(amount=4, quiz_type='boolean'):
5+
6+
def fetch_quiz_data(amount=4, quiz_type="boolean"):
67
url = f"https://opentdb.com/api.php?amount={amount}&type={quiz_type}"
78
response = requests.get(url)
89
data_json = response.json()
910
return data_json["results"]
1011

12+
1113
def check_answer(question, answer, score):
12-
correct_answer = html.unescape(question['correct_answer']).lower()
14+
correct_answer = html.unescape(question["correct_answer"]).lower()
1315
answer = answer.lower()
14-
16+
1517
if answer == correct_answer:
1618
print("Correct Answer! \nYour score is", score + 1)
1719
return True
@@ -20,6 +22,7 @@ def check_answer(question, answer, score):
2022
print(f"The correct answer is {html.unescape(question['correct_answer'])}")
2123
return False
2224

25+
2326
def display_question(question, question_number, score):
2427
print("\n" * 10)
2528
print("=" * 50)
@@ -29,9 +32,10 @@ def display_question(question, question_number, score):
2932
print(f"\tCategory: {question['category']}")
3033
print("=" * 50)
3134
print()
32-
print("Question: ", html.unescape(question['question']))
35+
print("Question: ", html.unescape(question["question"]))
3336
print()
3437

38+
3539
def main():
3640
quiz_data = fetch_quiz_data()
3741
score = 0
@@ -62,5 +66,6 @@ def main():
6266
print("Your final score is", score, "!")
6367
print("Thanks for playing! 💜")
6468

69+
6570
if __name__ == "__main__":
6671
main()

0 commit comments

Comments
 (0)