Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bob #10

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Bob #10

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion practice/bob/bob.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,43 @@
def response(hey_bob):
pass
"""
Respond to a statement or question directed at 'Bob'.

The function takes a string as input, representing something said to Bob.
Bob's responses are based on the following rules:

- Bob answers 'Sure.' if you ask him a question.
- He answers 'Whoa, chill out!' if you yell at him (ALL CAPS).
- He says 'Calm down, I know what I'm doing!' if you yell a question at him.
- He says 'Fine. Be that way!' if you address him without actually saying anything.
- He answers 'Whatever.' to anything else.

Args:
hey_bob (str): The statement or question directed at Bob.

Returns:
str: Bob's response.

Examples:
>>> response('Hello, Bob.')
'Whatever.'
>>> response('BOB!')
'Whoa, chill out!'
"""
# Remove trailing whitespace
hey_bob = hey_bob.rstrip()

# Check for an empty string
if hey_bob == '':
return "Fine. Be that way!"
# Check for shouting (all uppercase)
elif hey_bob.isupper():
# Check for a shouted question
if hey_bob.endswith('?'):
return "Calm down, I know what I'm doing!"
else:
return "Whoa, chill out!"
# Check for a question
elif hey_bob.endswith('?'):
return "Sure."
else:
return "Whatever."
Loading