-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.py
More file actions
80 lines (49 loc) · 1.73 KB
/
Copy pathMain.py
File metadata and controls
80 lines (49 loc) · 1.73 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Importing random
from random import randint
# =============================================================
# PYTHON MAGIC 8BALL CONSOLE APPLICATION
# Kenneth Melendez
# =============================================================
# ==============================================
# Data Validation
# ==============================================
# Check if variable is an int for data validation
def check_if_int(variable):
try:
int(variable)
return True
except ValueError:
return False
# ==============================================
# Messages and Promps
# ==============================================
# Method for returning a response for the user
def response(question):
print(f"{question}.. ?")
responses = ["Yes", "No", "Maybe"]
print(responses[randint(0, len(responses) - 1)])
# Method for prompting the user for a response and checking for an answer (Data Validation)
def prompt_question():
response = "Ask me a question!"
user_input = input(response)
while user_input == "" or check_if_int(user_input):
if check_if_int(user_input):
print("Hey that's a number!")
user_input = input("Please input a correct response")
return user_input
# Introduction prompt
def display_introduction():
print("Welcome to the Magic 8 Ball Application")
# GoodBye Message
def goodbye_msg():
print("GoodBye!")
# ==============================================
# Main Application Method
# ==============================================
# Main application method everything will load here
def run_application():
display_introduction()
response(prompt_question())
goodbye_msg()
# Loading Application
run_application()