Skip to content

Instantly share code, notes, and snippets.

@twonds
Created January 25, 2014 01:27
Show Gist options
  • Save twonds/8610329 to your computer and use it in GitHub Desktop.
Save twonds/8610329 to your computer and use it in GitHub Desktop.
# 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