2.19. Emotional Chatbot ¶
You want to create a chatbot that can understand when the human on the
other end is sad. So you want to be able to recognize texts like
"uhu", "uhuh","uhuhu"...
.Write a program that prints
"Are you sad, hooman?"
to the screen
if the given input is in the form \((\texttt{uh})^n\) or
\((\texttt{uh})^n \texttt{u}\) where exponent \(n\) denotes
\(n\) times repetition of the characters in the parantheses.
Otherwise, the program should print "I am so sad, hooman."
.Sample I/O:
Input:
uhuhuhuh
Output:
Are you sad, hooman?
Input:
hahahahah
Output:
I am so sad, hooman.
human = input()
human_says = list(human)
n = len(human_says)
right_count = 0
for i in range(0,n):
if i%2 == 0:
if human_says[i] == 'u':
right_count = right_count + 1
else:
if human_says[i] == 'h':
right_count = right_count + 1
if right_count == n:
print("Are you sad, hooman?")
else:
print("I am so sad, hooman.")