-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q_and_A.py
36 lines (30 loc) · 880 Bytes
/
Q_and_A.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
q_and_a = {"How are you?": "Good",
"What are you doing?": "I am programming",
"How's weather?": "Snowy"}
#def ask_user(q_and_a):
#try:
#while True:
#question = input("Ask a question: ")
#if question in q_and_a:
#print(q_and_a[question])
#elif question == "Bye":
#break
#else:
#print("Let's try again.")
#except KeyboardInterrupt:
#print("Sorry to see you go!")
def get_answer(question, q_and_a):
return q_and_a.get(question)
def ask_user(answers):
try:
while True:
user_question = input("Ask a question: ")
answer = get_answer(user_question, q_and_a)
print(answer)
if user_question == "Bye":
print("Sorry to see you go!")
break
except KeyboardInterrupt:
print("Sorry to see you go!")
if __name__ == "__main__":
ask_user(q_and_a)