|
1 | 1 | import random
|
| 2 | +from colorama import Fore, Style |
| 3 | +import inquirer |
2 | 4 |
|
3 | 5 | responses = [
|
4 | 6 | "It is certain",
|
5 | 7 | "It is decidedly so",
|
6 | 8 | "Without a doubt",
|
7 |
| - "Yes definitely ", |
| 9 | + "Yes definitely", |
8 | 10 | "You may rely on it",
|
9 | 11 | "As I see it, yes",
|
10 |
| - "Most likely ", |
| 12 | + "Most likely", |
11 | 13 | "Outlook good",
|
12 | 14 | "Yes",
|
13 | 15 | "Signs point to yes",
|
14 | 16 | "Do not count on it",
|
15 | 17 | "My reply is no",
|
16 |
| - " My sources say no", |
17 |
| - " Outlook not so good", |
| 18 | + "My sources say no", |
| 19 | + "Outlook not so good", |
18 | 20 | "Very doubtful",
|
19 | 21 | "Reply hazy try again",
|
20 | 22 | "Ask again later",
|
21 |
| - "Better not tell you now ", |
22 |
| - "Cannot predict now ", |
| 23 | + "Better not tell you now", |
| 24 | + "Cannot predict now", |
23 | 25 | "Concentrate and ask again",
|
24 | 26 | ]
|
25 |
| -print("Hi! I am the magic 8 ball, what's your name?") |
26 |
| -name = input() |
27 |
| -print("Hello!" + name) |
28 |
| - |
29 |
| - |
30 |
| -def magic8Ball(): |
31 |
| - print("Whay's your question? ") |
32 |
| - question = input() |
33 |
| - answer = responses[random.randint(0, len(responses) - 1)] |
34 |
| - print(answer) |
35 |
| - tryAgain() |
36 |
| - |
37 |
| - |
38 |
| -def tryAgain(): |
39 |
| - print( |
40 |
| - "Do you wanna ask any more questions? press Y for yes and any other key to exit " |
41 |
| - ) |
42 |
| - x = input() |
43 |
| - if x in ["Y", "y"]: |
44 |
| - magic8Ball() |
| 27 | + |
| 28 | + |
| 29 | +# Will use a class on it. |
| 30 | +# Will try to make it much more better. |
| 31 | +def get_user_name(): |
| 32 | + return inquirer.text( |
| 33 | + message="Hi! I am the magic 8 ball, what's your name?" |
| 34 | + ).execute() |
| 35 | + |
| 36 | + |
| 37 | +def display_greeting(name): |
| 38 | + print(f"Hello, {name}!") |
| 39 | + |
| 40 | + |
| 41 | +def magic_8_ball(): |
| 42 | + question = inquirer.text(message="What's your question?").execute() |
| 43 | + answer = random.choice(responses) |
| 44 | + print(Fore.BLUE + Style.BRIGHT + answer + Style.RESET_ALL) |
| 45 | + try_again() |
| 46 | + |
| 47 | + |
| 48 | +def try_again(): |
| 49 | + response = inquirer.list_input( |
| 50 | + message="Do you want to ask more questions?", |
| 51 | + choices=["Yes", "No"], |
| 52 | + ).execute() |
| 53 | + |
| 54 | + if response.lower() == "yes": |
| 55 | + magic_8_ball() |
45 | 56 | else:
|
46 | 57 | exit()
|
47 | 58 |
|
48 | 59 |
|
49 |
| -magic8Ball() |
| 60 | +if __name__ == "__main__": |
| 61 | + user_name = get_user_name() |
| 62 | + display_greeting(user_name) |
| 63 | + magic_8_ball() |
0 commit comments