YoYoYo I&#39;m Awesome - 1 year ago 142
Python Question

Exercism Python Bob

I'm learning Python through Exercism.IO, I'm currently on the

`Bob`
problem where the object of the problem is as follows:

Bob is a lackadaisical teenager. In conversation, his responses are very limited.
He answers 'Whoa, chill out!' if you yell at him.
He says 'Fine. Be that way!' if you address him without actually saying
anything.
He answers 'Whatever.' to anything else.

So far I've passed a few tests and I'm stuck at a point where it's suppose to return
`whatever`
but all the characters are integers, so of course it's not working.

Here's where I'm failing:

``````def test_only_numbers(self):
self.assertEqual(
'Whatever.', bob.hey('1, 2, 3')
)
``````

All the characters are integers and my test to see if they're yelling looks like this:

``````def is_yelling(self):
return self.sentence == self.sentence.upper()
``````

Obviously the characters are the same when upper or lower case because they're numbers so the program thinks they're yelling. My question is how can I refactor this program to make it so that when the assertion is all numbers, it won't count it as yelling?

``````def hey(what):
sentence = SentenceThinker(what)
if sentence.is_silence():
return "Fine. Be that way!"
elif sentence.is_yelling():
return "Whoa, chill out!"
elif sentence.is_question():
return "Sure."
else:
return "Whatever."

class SentenceThinker(object):

def __init__(self, sentence):
self.sentence = sentence

def is_yelling(self):
return self.sentence == self.sentence.upper()

def is_question(self):
return self.sentence.endswith("?")

def is_silence(self):
return not self.sentence
``````

consider using the built-in String method `str.isupper()`