forked from BestTeeChur/Python-Assignment-4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8ball.py
More file actions
52 lines (46 loc) · 2.13 KB
/
8ball.py
File metadata and controls
52 lines (46 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import random
import time
#This section creates a list of all the possible replies and prints out an ASCII 8ball with a pause between each line. This is to indicate that the code has started running.
answers = ["It is certain", "It is decidely 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"]
print(" .-'''-.")
time.sleep(.5)
print(" / _ \\")
time.sleep(.5)
print(" | (8) |")
time.sleep(.5)
print(" \ ^ /")
time.sleep(.5)
print(" '-...-'")
#The main function of the 8ball.
def ask_eight_ball():
#asks the user to input a name and questions. .upper() turns the string into all caps.
print("Hello! Welcome to Pj's Magic 8 ball")
name = input("What is your name? ")
#capitalizes the name
cap_name = name.upper()
question = input("What is your question? ")
cap_question = question.upper()
#This uses random to create a random integer between two numbers, in this case 0 and the length of the list minus 1 to account for 0 indexing.
get_the_i = random.randint(0, len(answers))
#this selectes the answer by using the random number as the index from the list
answer = answers[get_the_i]
#fun filler to pretend like it's thinking
print(f"{cap_name}, you asked '{cap_question}'.")
print("Pondering the Orb")
time.sleep(random.randint(1, 5))
print("🔮 ✨ 🔮")
time.sleep(1)
print(f"{answer}")
ask_again = input("Would you like to ask again? yes/no ")
#runs play again to check if user wants another round
#if the user wants to play again, this function is called to ask the question again
if ask_again == "yes" or "y":
play_again()
else:
pass
#play again is the logic for deciding how the player answered about another question
def play_again():
# write this function
ask_eight_ball()
#runs the game function
ask_eight_ball()