Skip to content

Commit 641e756

Browse files
update: add good features
More good features were added.
1 parent dd0534c commit 641e756

File tree

3 files changed

+130
-45
lines changed

3 files changed

+130
-45
lines changed

love_turtle.py

+26-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
import turtle
22

3-
t = turtle.Turtle()
4-
turtle.title("I Love You")
5-
screen = turtle.Screen()
6-
screen.bgcolor("white")
7-
t.color("red")
8-
t.begin_fill()
9-
t.fillcolor("black")
10-
11-
t.left(140)
12-
t.forward(180)
13-
t.circle(-90, 200)
14-
15-
t.setheading(60) # t.left
16-
t.circle(-90, 200)
17-
t.forward(180)
18-
19-
t.end_fill()
20-
t.hideturtle()
3+
4+
def heart_red():
5+
t = turtle.Turtle()
6+
turtle.title("I Love You")
7+
screen = turtle.Screen()
8+
screen.bgcolor("white")
9+
t.color("red")
10+
t.begin_fill()
11+
t.fillcolor("red")
12+
13+
t.left(140)
14+
t.forward(180)
15+
t.circle(-90, 200)
16+
17+
t.setheading(60) # t.left
18+
t.circle(-90, 200)
19+
t.forward(180)
20+
21+
t.end_fill()
22+
t.hideturtle()
23+
24+
turtle.done()
25+
26+
27+
if __name__ == "__main__":
28+
heart_red()

magic8ball.py

+41-27
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,63 @@
11
import random
2+
from colorama import Fore, Style
3+
import inquirer
24

35
responses = [
46
"It is certain",
57
"It is decidedly so",
68
"Without a doubt",
7-
"Yes definitely ",
9+
"Yes definitely",
810
"You may rely on it",
911
"As I see it, yes",
10-
"Most likely ",
12+
"Most likely",
1113
"Outlook good",
1214
"Yes",
1315
"Signs point to yes",
1416
"Do not count on it",
1517
"My reply is no",
16-
" My sources say no",
17-
" Outlook not so good",
18+
"My sources say no",
19+
"Outlook not so good",
1820
"Very doubtful",
1921
"Reply hazy try again",
2022
"Ask again later",
21-
"Better not tell you now ",
22-
"Cannot predict now ",
23+
"Better not tell you now",
24+
"Cannot predict now",
2325
"Concentrate and ask again",
2426
]
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()
4556
else:
4657
exit()
4758

4859

49-
magic8Ball()
60+
if __name__ == "__main__":
61+
user_name = get_user_name()
62+
display_greeting(user_name)
63+
magic_8_ball()

magic_8_ball.py

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import random
2+
from colorama import Fore, Style
3+
import inquirer
4+
5+
responses = [
6+
"It is certain",
7+
"It is decidedly so",
8+
"Without a doubt",
9+
"Yes definitely",
10+
"You may rely on it",
11+
"As I see it, yes",
12+
"Most likely",
13+
"Outlook good",
14+
"Yes",
15+
"Signs point to yes",
16+
"Do not count on it",
17+
"My reply is no",
18+
"My sources say no",
19+
"Outlook not so good",
20+
"Very doubtful",
21+
"Reply hazy try again",
22+
"Ask again later",
23+
"Better not tell you now",
24+
"Cannot predict now",
25+
"Concentrate and ask again",
26+
]
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()
56+
else:
57+
exit()
58+
59+
60+
if __name__ == "__main__":
61+
user_name = get_user_name()
62+
display_greeting(user_name)
63+
magic_8_ball()

0 commit comments

Comments
 (0)