# import module for calling random() import random # create a dict of the possible answers answers = { 1: "It is certain", 2: "It is decidedly so", 3: "Without a doubt", 4: "Yes definitely", 5: "You may rely on it", 6: "As I see it, yes", 7: "Most likely", 8: "Outlook good", 9: "Yes", 10: "Signs point to yes", 11: "Reply hazy try again", 12: "Ask again later", 13: "Better not tell you now", 14: "Cannot predict now", 15: "Concentrate and ask again", 16: "Don't count on it", 17: "My reply is no", 18: "My sources say no", 19: "Outlook not so good", 20: "Very doubtful" } # assign the 8-ball's response to a random integer b/n 1-20 response = random.randint(1,20) # get the user input (the question) question = raw_input('What is your question? ') # print the user input (the question) print('\n\nYou asked: %s\n' % question) # print the answer string print('Muh answer: %s' % answers[response])
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question