Created
January 25, 2014 01:27
-
-
Save twonds/8610329 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# bob | |
import string | |
class Bob(object): | |
def hey(self, spoken): | |
words = spoken.strip() | |
# Default response | |
response = "Whatever." | |
if self.isBlank(words): | |
# Response to blank | |
response = 'Fine. Be that way!' | |
else: | |
if self.isQuestion(words): | |
# Response to question | |
response = 'Sure.' | |
if self.isYelling(words): | |
# Response to yelling, question or not | |
response = 'Woah, chill out!' | |
return response | |
def isQuestion(self, words): | |
return words[-1] == '?' | |
def isBlank(self, words): | |
return words == "" | |
def isYelling(self, words): | |
letters = "" | |
letters_upper = "" | |
for c in words: | |
# ignore characters that are the same upper or lower | |
if c not in string.digits + string.punctuation + string.whitespace: | |
letters += c | |
letters_upper += c.upper() | |
return letters != "" and letters == letters_upper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment