- Saved searches
- Use saved searches to filter your results more quickly
- Antariex/Magic-8-Ball
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- Python Projects: Magic 8 Ball for fortune-telling or seeking advice
- happy-box / magic_8_ball.py
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
A simple Magic 8-Ball game written on Python (Codecademy project).
Antariex/Magic-8-Ball
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Intro to programming: Magic 8-Ball game (CodeCademy project):
The Magic 8-Ball is a popular toy developed in the 1950s for fortune-telling or advice seeking.
This is a simple Python program that can answer any “Yes” or “No” question with a different fortune each time it executes.
Magic 8-Ball, should I do this project?
This little program will be using the following 9 possible answers for our Magic 8-Ball (plus 3 others that you will have to discover by yourself!):
- Yes — definitely
- It is decidedly so
- Without a doubt
- Reply hazy, try again
- Ask again later
- Better not tell you now
- My sources say no
- Outlook not so good
- Very doubtful
The output of the program will have the following format:
[Name] asks: [Question] Magic 8-Ball’s answer: [Answer]For example:
Joe asks: Is this real life?
Magic 8-Ball’s answer: Better not tell you now
About
A simple Magic 8-Ball game written on Python (Codecademy project).
Python Projects: Magic 8 Ball for fortune-telling or seeking advice
Create a Python project of a Magic 8 Ball which is a toy used for fortune-telling or seeking advice.
- Allow the user to input their question.
- Show an in progress message.
- Create 10/20 responses, and show a random response.
- Allow the user to ask another question/advice or quit the game.
Sample Solution -1 :
Python Code:
#Make a Magic 8 ball #https://github.com/viljow/magic8/blob/master/main.py import random answers = ['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', 'Reply hazy', 'try again', 'Ask again later', 'Better not tell you now', 'Cannot predict now', 'Concentrate and ask again', 'Dont count on it', 'My reply is no', 'My sources say no', 'Outlook not so good', 'Very doubtful'] print(' __ __ _____ _____ _____ ___ ') print(' | \/ | /\ / ____|_ _/ ____| / _ \ ') print(' | \ / | / \ | | __ | || | | (_) |') print(' | |\/| | / /\ \| | |_ | | || | > _ < ') print(' | | | |/ ____ \ |__| |_| || |____ | (_) |') print(' |_| |_/_/ \_\_____|_____\_____| \___/ ') print('') print('') print('') print('Hello World, I am the Magic 8 Ball, What is your name?') name = input() print('hello ' + name) def Magic8Ball(): print('Ask me a question.') input() print (answers[random.randint(0, len(answers)-1)] ) print('I hope that helped!') Replay() def Replay(): print ('Do you have another question? [Y/N] ') reply = input() if reply == 'Y': Magic8Ball() elif reply == 'N': exit() else: print('I apologies, I did not catch that. Please repeat.') Replay() Magic8Ball()
__ __ _____ _____ _____ ___ | \/ | /\ / ____|_ _/ ____| / _ \ | \ / | / \ | | __ | || | | (_) | | |\/| | / /\ \| | |_ | | || | > _ < | | | |/ ____ \ |__| |_| || |____ | (_) | |_| |_/_/ \_\_____|_____\_____| \___/ Hello World, I am the Magic 8 Ball, What is your name? Sara hello Sara Ask me a question. Tell my fortune It is certain I hope that helped! Do you have another question? [Y/N] Y Ask me a question. My favorite color My reply is no I hope that helped! Do you have another question? [Y/N] N
Sample Solution -2 :
Python Code:
#https://github.com/soupyck/Magic8Ball/blob/master/magic8ball.py import random import time eight_ball = [ "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", "Reply hazy, try again", "Ask again later", "Better not tell you now", "Cannot predict now", "Concentrate and ask again", "Don't count on it", "My reply is no", "My sources say no", "Outlook not so good", "Very Doubtful"] def question(): question = input("You may ask your yes or no question of the Magic 8 Ball!\n") print("Thinking. ") time.sleep(random.randrange(0,5)) print(random.choice(eight_ball)) while True: question() repeat = input("Would you like to ask another question? (Y or N)") if not (repeat == "y" or repeat == "Y"): print("Come back if you have more questions!") break
You may ask your yes or no question of the Magic 8 Ball! Tell me my fortune Thinking. You may rely on it Would you like to ask another question? (Y or N)Y You may ask your yes or no question of the Magic 8 Ball! yes Thinking. Yes, definitely Would you like to ask another question? (Y or N)n Come back if you have more questions!
Sample Solution -3 :
Python Code:
https://github.com/pixelnull/8ball/blob/master/8ball.py import random import time # Set count to how many times user wants to do the magic 8ball count_str = input("Hello user. How many questions would you like to ask the 8-Ball? ") # Handling if count_str is not a number while True: if count_str.isdigit(): count = int(count_str) break else: count_str = input("You cheeky devil, just enter a simple number this time: ") # Outlier input handling if count 10: print("\nYou have to be kidding me, you want to do that many questions?\nWe'll do 1 and go from there.\n", sep='') count = 1 # Sequence for random.choice answers = ["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.", "Reply hazy try again.", "Ask again later.", "Better not tell you now.", "Cannot predict now.", "Concentrate and ask again.", "Don\'t count on it.", "My reply is no.", "My sources say no.", "Outlook not so good.", "Very doubtful."] # Main loop and graceful exit while count > 0: blah = input("Type your question: ") dice = random.choice(answers) print("\n", dice, "\n", sep='') time.sleep(2) count = count - 1 else: print("\nI hope you liked the answer(s). THE GREAT 8-BALL HAS SPOKEN!") time.sleep(5) exit()
Hello user. How many questions would you like to ask the 8-Ball? 1 Type your question: Tell me my fortune Signs point to yes. I hope you liked the answer(s). THE GREAT 8-BALL HAS SPOKEN!
Sample Solution -4 :
Python Code:
#https://github.com/DeronKHolmes/magic-8-ball-game/blob/master/eightball.py import random import time, sys play_again = 'yes' while play_again == 'yes': str(input("Welcome to the Magic 8-Ball. Enter your question: ")).lower() #Delay output for 1 second each print("Thinking. ") time.sleep(1) print("3. ") time.sleep(1) print("2. ") time.sleep(1) print("1. ") time.sleep(1) print() #Generate a random integer/response response = random.randint(0,20) if response == 1: print("Not just no, hell no!") elif response == 2: print("Sure thing.") elif response == 3: print("Don't count on it.") elif response == 4: print("Maybe not.") elif response == 5: print("Count on it.") elif response == 6: print("The Universe says maybe.") elif response == 7: print("I don't see why not.") elif response == 8: print("The future looks good for you.") elif response == 9: print("That's for sure.") elif response == 10: print("Maybe.") elif response == 11: print("There's a chance.") elif response == 12: print("Certainly!") elif response == 13: print("Keep doing what you're doing and it'll happen.") elif response == 14: print("Not over my dead 8 Ball.") elif response == 15: print("No.") elif response == 16: print("Yes.") elif response == 17: print("All depends on if you've been good for Santa this year.") elif response == 18: print("Not in this lifetime.") elif response == 19: print("Someday, but not today.") elif response == 20: print("Right after you hit the lottery.") else: print("Not a valid question!") play_again = str(input("Would you like to ask another question? yes/no ")).lower() if play_again == 'no': print("Goodbye! Thanks for playing!") sys.exit()
Welcome to the Magic 8-Ball. Enter your question: Tell me my fortune Thinking. 3. 2. 1. Maybe not. Would you like to ask another question? yes/no yes Welcome to the Magic 8-Ball. Enter your question: My favorite color Thinking. 3. 2. 1. No. Would you like to ask another question? yes/no no Goodbye! Thanks for playing!
Contribute your code and comments through Disqus.
Follow us on Facebook and Twitter for latest update.
happy-box / magic_8_ball.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 |
# Magic 8 Ball IRC bot |
# Created by Lance Brignoni |
# This program is free software; you can redistribute it and/or modify |
# it under the terms of the GNU General Public License as published by |
# the Free Software Foundation; either version 3 of the License, or |
# (at your option) any later version. |
# |
# This program is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
# GNU General Public License for more details. |
# |
# You should have received a copy of the GNU General Public License along |
# with this program; if not, write to the Free Software Foundation, Inc., |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
import random |
import time |
responses = [ "Not so sure" , "42" , "Most likely" , "Absolutely not" , "Outlook is good" , "I see good things happening" , "Never" , |
"Negative" , "Could be" , "Unclear, ask again" , "Yes" , "No" , "Possible, but not probable" ] |
## Following function asks user question, then returns random results from responses |
def answerQuery (): |
question = input ( "Ask and you shall receive: " ) |
print ( "Let me dig deep into the waters of life, and find your answer" ) |
time . sleep ( 2 ) |
print ( "Hmmm" ) |
time . sleep ( 2 ) |
print ( random . choice ( responses )) |
print ( " \n " ) |
answerQuery () |
## Following asks user if they would like to play again, and loops until user is finished |
secondQuestion = ( input ( "Would you like to ask the Wise One another question? Y/N: " )) |
while secondQuestion == str ( "Y" ): |
answerQuery () |
secondQuestion = ( input ( "Would you like to ask the Wise One another question? Y/N: " )) |
else : |
print ( input ( "Press any key to exit" )) |