diff --git a/love_turtle.py b/love_turtle.py index 82e0217205b..238b3eebf80 100644 --- a/love_turtle.py +++ b/love_turtle.py @@ -1,20 +1,28 @@ import turtle -t = turtle.Turtle() -turtle.title("I Love You") -screen = turtle.Screen() -screen.bgcolor("white") -t.color("red") -t.begin_fill() -t.fillcolor("black") - -t.left(140) -t.forward(180) -t.circle(-90, 200) - -t.setheading(60) # t.left -t.circle(-90, 200) -t.forward(180) - -t.end_fill() -t.hideturtle() + +def heart_red(): + t = turtle.Turtle() + turtle.title("I Love You") + screen = turtle.Screen() + screen.bgcolor("white") + t.color("red") + t.begin_fill() + t.fillcolor("red") + + t.left(140) + t.forward(180) + t.circle(-90, 200) + + t.setheading(60) # t.left + t.circle(-90, 200) + t.forward(180) + + t.end_fill() + t.hideturtle() + + turtle.done() + + +if __name__ == "__main__": + heart_red() diff --git a/magic8ball.py b/magic8ball.py index 1ce9dc39a69..816705b8e21 100644 --- a/magic8ball.py +++ b/magic8ball.py @@ -1,49 +1,63 @@ import random +from colorama import Fore, Style +import inquirer responses = [ "It is certain", "It is decidedly so", "Without a doubt", - "Yes definitely ", + "Yes definitely", "You may rely on it", "As I see it, yes", - "Most likely ", + "Most likely", "Outlook good", "Yes", "Signs point to yes", "Do not count on it", "My reply is no", - " My sources say no", - " Outlook not so good", + "My sources say no", + "Outlook not so good", "Very doubtful", "Reply hazy try again", "Ask again later", - "Better not tell you now ", - "Cannot predict now ", + "Better not tell you now", + "Cannot predict now", "Concentrate and ask again", ] -print("Hi! I am the magic 8 ball, what's your name?") -name = input() -print("Hello!" + name) - - -def magic8Ball(): - print("Whay's your question? ") - question = input() - answer = responses[random.randint(0, len(responses) - 1)] - print(answer) - tryAgain() - - -def tryAgain(): - print( - "Do you wanna ask any more questions? press Y for yes and any other key to exit " - ) - x = input() - if x in ["Y", "y"]: - magic8Ball() + + +# Will use a class on it. +# Will try to make it much more better. +def get_user_name(): + return inquirer.text( + message="Hi! I am the magic 8 ball, what's your name?" + ).execute() + + +def display_greeting(name): + print(f"Hello, {name}!") + + +def magic_8_ball(): + question = inquirer.text(message="What's your question?").execute() + answer = random.choice(responses) + print(Fore.BLUE + Style.BRIGHT + answer + Style.RESET_ALL) + try_again() + + +def try_again(): + response = inquirer.list_input( + message="Do you want to ask more questions?", + choices=["Yes", "No"], + ).execute() + + if response.lower() == "yes": + magic_8_ball() else: exit() -magic8Ball() +if __name__ == "__main__": + user_name = get_user_name() + display_greeting(user_name) + magic_8_ball() diff --git a/magic_8_ball.py b/magic_8_ball.py new file mode 100644 index 00000000000..816705b8e21 --- /dev/null +++ b/magic_8_ball.py @@ -0,0 +1,63 @@ +import random +from colorama import Fore, Style +import inquirer + +responses = [ + "It is certain", + "It is decidedly so", + "Without a doubt", + "Yes definitely", + "You may rely on it", + "As I see it, yes", + "Most likely", + "Outlook good", + "Yes", + "Signs point to yes", + "Do not count on it", + "My reply is no", + "My sources say no", + "Outlook not so good", + "Very doubtful", + "Reply hazy try again", + "Ask again later", + "Better not tell you now", + "Cannot predict now", + "Concentrate and ask again", +] + + +# Will use a class on it. +# Will try to make it much more better. +def get_user_name(): + return inquirer.text( + message="Hi! I am the magic 8 ball, what's your name?" + ).execute() + + +def display_greeting(name): + print(f"Hello, {name}!") + + +def magic_8_ball(): + question = inquirer.text(message="What's your question?").execute() + answer = random.choice(responses) + print(Fore.BLUE + Style.BRIGHT + answer + Style.RESET_ALL) + try_again() + + +def try_again(): + response = inquirer.list_input( + message="Do you want to ask more questions?", + choices=["Yes", "No"], + ).execute() + + if response.lower() == "yes": + magic_8_ball() + else: + exit() + + +if __name__ == "__main__": + user_name = get_user_name() + display_greeting(user_name) + magic_8_ball()