Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

review file #1535

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 40 additions & 25 deletions magic8.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
import random
import logging

logging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s')

name = "Joe"
question = "Will I win the lottery?"
question = ""
answer = ""

random_number = random.randint(1, 9)
# print(random_number)
question = input("Ask a question: ")

if random_number == 1:
answer = "Yes - definitely"
elif random_number == 2:
answer = "It is decidedly so"
elif random_number == 3:
answer = "Without a doubt"
elif random_number == 4:
answer = "Reply hazy, try again"
elif random_number == 5:
answer = "Ask again later"
elif random_number == 6:
answer = "Better not tell you now"
elif random_number == 7:
answer = "My sources say no"
elif random_number == 8:
answer = "Outlook not so good"
elif random_number == 9:
answer = "Very doubtful"
if not question:
print("Please ask a question.")
else:
answer = "Error"

print(name + " asks: " + question)
print("Magic 8 Ball's answer: " + answer)
try:
random_number = random.randint(1, 9)
assert 1 <= random_number <= 9, "Random number out of range: {}".format(random_number)
except Exception as e:
logging.error("An error occurred: %s", str(e))
print("An error occurred. Please try again.")
else:
if random_number == 1:
answer = "Yes - definitely"
elif random_number == 2:
answer = "It is decidedly so"
elif random_number == 3:
answer = "Without a doubt"
elif random_number == 4:
answer = "Reply hazy, try again"
elif random_number == 5:
answer = "Ask again later"
elif random_number == 6:
answer = "Better not tell you now"
elif random_number == 7:
answer = "My sources say no"
elif random_number == 8:
answer = "Outlook not so good"
elif random_number == 9:
answer = "Very doubtful"

if not name:
print("Magic 8 Ball's answer: " + answer)
else:
print(name + " asks: " + question)
print("Magic 8 Ball's answer: " + answer)