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

victor escarcega
victor escarcega
5,439 Points

I believe my code is correct for the required output. Not sure why it is still not accepting my message

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,
)
message = input("What would you like to tweet?  ")
# Your code here

def tweet(words):
    print (words)

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

1 Answer

Josh Keenan
Josh Keenan
17,380 Points

You made a slight mistake. It has to be in one print statement not two. And you don't need to define the tweet function as they have done it for you, you only need to call it.

"""
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,
)


message = input("What would you like to tweet?  ")
# Your code here

try:
    tweet(message)
except CommunicationError:
    print("An error occurred attempting to connect to Twitter. Please try again!")
victor escarcega
victor escarcega
5,439 Points

I was receiving the error because i was defininf the function, once i deleted it I passed the challenge. Thank you!