-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathhello.py
189 lines (145 loc) · 5.71 KB
/
hello.py
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
"""
HELLO
A very simple "chat" bot.
Warning, the advice given here is bad.
Ported by Dave LeCompte
"""
import time
from typing import Optional, Tuple
def get_yes_or_no() -> Tuple[bool, Optional[bool], str]:
msg = input()
if msg.upper() == "YES":
return True, True, msg
elif msg.upper() == "NO":
return True, False, msg
else:
return False, None, msg
def ask_enjoy_question(user_name: str) -> None:
print(f"HI THERE, {user_name}, ARE YOU ENJOYING YOURSELF HERE?")
while True:
valid, value, msg = get_yes_or_no()
if valid:
if value:
print(f"I'M GLAD TO HEAR THAT, {user_name}.")
print()
else:
print(f"OH, I'M SORRY TO HEAR THAT, {user_name}. MAYBE WE CAN")
print("BRIGHTEN UP YOUR VISIT A BIT.")
break
else:
print(f"{user_name}, I DON'T UNDERSTAND YOUR ANSWER OF '{msg}'.")
print("PLEASE ANSWER 'YES' OR 'NO'. DO YOU LIKE IT HERE?")
def prompt_for_problems(user_name: str) -> str:
print()
print(f"SAY, {user_name}, I CAN SOLVE ALL KINDS OF PROBLEMS EXCEPT")
print("THOSE DEALING WITH GREECE. WHAT KIND OF PROBLEMS DO")
print("YOU HAVE? (ANSWER SEX, HEALTH, MONEY, OR JOB)")
return input().upper()
def prompt_too_much_or_too_little() -> Tuple[bool, Optional[bool]]:
answer = input().upper()
if answer == "TOO MUCH":
return True, True
elif answer == "TOO LITTLE":
return True, False
return False, None
def solve_sex_problem(user_name: str) -> None:
print("IS YOUR PROBLEM TOO MUCH OR TOO LITTLE?")
while True:
valid, too_much = prompt_too_much_or_too_little()
if valid:
if too_much:
print("YOU CALL THAT A PROBLEM?!! I SHOULD HAVE SUCH PROBLEMS!")
print(f"IF IT BOTHERS YOU, {user_name}, TAKE A COLD SHOWER.")
else:
print(f"WHY ARE YOU HERE IN SUFFERN, {user_name}? YOU SHOULD BE")
print("IN TOKYO OR NEW YORK OR AMSTERDAM OR SOMEPLACE WITH SOME")
print("REAL ACTION.")
return
else:
print(f"DON'T GET ALL SHOOK, {user_name}, JUST ANSWER THE QUESTION")
print("WITH 'TOO MUCH' OR 'TOO LITTLE'. WHICH IS IT?")
def solve_money_problem(user_name: str) -> None:
print(f"SORRY, {user_name}, I'M BROKE TOO. WHY DON'T YOU SELL")
print("ENCYCLOPEADIAS OR MARRY SOMEONE RICH OR STOP EATING")
print("SO YOU WON'T NEED SO MUCH MONEY?")
def solve_health_problem(user_name: str) -> None:
print(f"MY ADVICE TO YOU {user_name} IS:")
print(" 1. TAKE TWO ASPRIN")
print(" 2. DRINK PLENTY OF FLUIDS (ORANGE JUICE, NOT BEER!)")
print(" 3. GO TO BED (ALONE)")
def solve_job_problem(user_name: str) -> None:
print(f"I CAN SYMPATHIZE WITH YOU {user_name}. I HAVE TO WORK")
print("VERY LONG HOURS FOR NO PAY -- AND SOME OF MY BOSSES")
print(f"REALLY BEAT ON MY KEYBOARD. MY ADVICE TO YOU, {user_name},")
print("IS TO OPEN A RETAIL COMPUTER STORE. IT'S GREAT FUN.")
def alert_unknown_problem_type(user_name: str, problem_type: str) -> None:
print(f"OH, {user_name}, YOUR ANSWER OF {problem_type} IS GREEK TO ME.")
def ask_question_loop(user_name: str) -> None:
while True:
problem_type = prompt_for_problems(user_name)
if problem_type == "SEX":
solve_sex_problem(user_name)
elif problem_type == "HEALTH":
solve_health_problem(user_name)
elif problem_type == "MONEY":
solve_money_problem(user_name)
elif problem_type == "JOB":
solve_job_problem(user_name)
else:
alert_unknown_problem_type(user_name, problem_type)
while True:
print()
print(f"ANY MORE PROBLEMS YOU WANT SOLVED, {user_name}?")
valid, value, msg = get_yes_or_no()
if valid:
if not value:
return
print("WHAT KIND (SEX, MONEY, HEALTH, JOB)")
break
print(f"JUST A SIMPLE 'YES' OR 'NO' PLEASE, {user_name}.")
def ask_for_fee(user_name: str) -> None:
print()
print(f"THAT WILL BE $5.00 FOR THE ADVICE, {user_name}.")
print("PLEASE LEAVE THE MONEY ON THE TERMINAL.")
time.sleep(4)
print()
print()
print()
print("DID YOU LEAVE THE MONEY?")
while True:
valid, value, msg = get_yes_or_no()
if valid:
if value:
print(f"HEY, {user_name}, YOU LEFT NO MONEY AT ALL!")
print("YOU ARE CHEATING ME OUT OF MY HARD-EARNED LIVING.")
print()
print(f"WHAT A RIP OFF, {user_name}!!!")
print()
else:
print(f"THAT'S HONEST, {user_name}, BUT HOW DO YOU EXPECT")
print("ME TO GO ON WITH MY PSYCHOLOGY STUDIES IF MY PATIENTS")
print("DON'T PAY THEIR BILLS?")
return
else:
print(f"YOUR ANSWER OF '{msg}' CONFUSES ME, {user_name}.")
print("PLEASE RESPOND WITH 'YES' or 'NO'.")
def unhappy_goodbye(user_name: str) -> None:
print()
print(f"TAKE A WALK, {user_name}.")
print()
print()
def happy_goodbye(user_name: str) -> None:
print(f"NICE MEETING YOU, {user_name}, HAVE A NICE DAY.")
def main() -> None:
print(" " * 33 + "HELLO")
print(" " * 15 + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n\n\n")
print("HELLO. MY NAME IS CREATIVE COMPUTER.\n\n")
print("WHAT'S YOUR NAME?")
user_name = input()
print()
ask_enjoy_question(user_name)
ask_question_loop(user_name)
ask_for_fee(user_name)
unhappy_goodbye(user_name)
if __name__ == "__main__":
main()