Skip to content

Commit 41b7351

Browse files
committed
corrected engine.py, brain_even.py
1 parent 6e507af commit 41b7351

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

brain_games/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
def welcome_user():
55
print("Welcome to the Brain Games!")
6-
name = prompt.string('May I have your name? ')
6+
name = prompt.string("May I have your name? ")
77
print(f"Hello, {name}!")

brain_games/engine.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
def run_game(game_description: str, generate_round) -> None:
55
print("Welcome to the Brain Games!")
6-
name = prompt.string('May I have your name? ')
6+
name = prompt.string("May I have your name? ")
77
print(f"Hello, {name}!")
88

99
print(game_description)
@@ -15,7 +15,10 @@ def run_game(game_description: str, generate_round) -> None:
1515
user_answer = prompt.string("Your answer: ")
1616

1717
if user_answer != correct_answer:
18-
print(f"'{user_answer}' is wrong answer ;(. Correct answer was '{correct_answer}'.")
18+
print(
19+
f"'{user_answer}' is wrong answer ;(."
20+
f" Correct answer was '{correct_answer}'."
21+
)
1922
print(f"Let's try again, {name}!")
2023
return
2124

brain_games/games/even.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import random
1+
import secrets
22

33

44
def is_even(number: int) -> bool:
@@ -7,8 +7,8 @@ def is_even(number: int) -> bool:
77

88
def generate_round() -> tuple[str, str]:
99
"""Generate a round for the even game."""
10-
# For game purposes, using random is safe here
11-
number = random.randint(1, 100)
10+
# Using secrets for cryptographically secure randomness
11+
number = secrets.randbelow(100) + 1 # 1-100
1212
question = str(number)
13-
correct_answer = 'yes' if is_even(number) else 'no'
13+
correct_answer = "yes" if is_even(number) else "no"
1414
return question, correct_answer

brain_games/scripts/brain_even.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ def main():
1010
run_game(DESCRIPTION, generate_round)
1111

1212

13-
if __name__ == '__main__':
13+
if __name__ == "__main__":
1414
main()

0 commit comments

Comments
 (0)