Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Practice Creating and Using Functions in Python Practice Functions Use an External Function

don't understand the syntax of this challenge

using_a_function.py
"""
This is importing a function named `tweet` from a file
    that we unfortunately don't have access to change.

You use it like so:
>>> tweet("Hello this is my tweet")

If the function cannot connect to Twitter,
    the function will raise a `CommunicationError`
If the message is too long,
    the function will raise a `MessageTooLongError`
"""
from twitter import (
    tweet,
    MessageTooLongError,
    CommunicationError,
)


try:
    tweet(message)
        message = input("What would you like to tweet?  ")


except CommunicationError:
    print("An error occurred attempting to connect to Twitter. Please try again")

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, merrill sequeira ! It looks like you're off to a pretty good start. You obviously made it past the first step.

Here are a couple of tips to help you along. You should leave the definition of message where it is in the code and only write your code below the comment line that was originally displayed. Right now, you are trying to tweet the message before you've gotten the message to tweet out from the user.

The line that assigns the input from the user to the variable message should come before the try and except blocks. Inside the try, call the function tweet and pass in message, just as you've done above. Then in the except block, print the error message you have.

Really, the problem here is placement. First, get the message. Then try to tweet the message. If there was a communication error, print the error.

Hope this helps! :sparkles: