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

merrill sequeira
merrill sequeira
2,874 Points

don't understand the syntax of this challenge
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 (

        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
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: