Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions BasicPythonScripts/Magic 8-Ball/Magic_8_Ball.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Import the modules
import sys
import random

ans = True

while ans:
question = input("Ask the magic 8 ball a question: (press enter to quit) ")

answers = random.randint(1,8)

if question == "":
sys.exit()

elif answers == 1:
print("It is certain")

elif answers == 2:
print("Outlook good")

elif answers == 3:
print("You may rely on it")

elif answers == 4:
print("Ask again later")

elif answers == 5:
print("Concentrate and ask again")

elif answers == 6:
print("Reply hazy, try again")

elif answers == 7:
print("My reply is no")

elif answers == 8:
print("My sources say no")
36 changes: 36 additions & 0 deletions BasicPythonScripts/Magic 8-Ball/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# MAGIC 8 BALL

## AIM
To generate random answers to questions asked to the Magic 8 Ball

## PURPOSE
The Magic 8 Ball is a toy used for fortune-telling or seeking advice.

## MODULES USED
Sys : The sys module in Python provides various functions and variables that are used to manipulate different parts of the Python runtime environment. It allows operating on the interpreter as it provides access to the variables and functions that interact strongly with the interpreter.

Random : This module implements pseudo-random number generators for various distributions.
For integers, there is uniform selection from a range. For sequences, there is uniform selection of a random element, a function to generate a random permutation of a list in-place, and a function for random sampling without replacement.

## WORKFLOW
- First of all, we would import sys and random modules from the python library
- Declare a boolean value(True) to ans variable
- Setup a while loop which works until the value remains True
- Ask any random question to which we want answer
- Using randint func generate random a random number from 1-8
- Now using elif ladder, generate a random answer based on the question and print it

## SETUP INSTRUCTIONS
User needs a Python IDE to run the program

## OUTPUT
![Code](Images/Magic_8_Ball.py - Magic 8-Ball - Visual Studio Code 12_10_2021 2_33_43 pm.png)


![Output](Images/Magic_8_Ball.py - Magic 8-Ball - Visual Studio Code 12_10_2021 2_34_33 pm.png)

## AUTHOR
YASH KATARIA

## FOR ANY DOUBTS
www.linkedin.com/in/kataria-yash