NameError: name 'text' is not defined in Python basic print (trump_tweet(text))

Asked 1 weeks ago, Updated 1 weeks ago, 1 views

------------------- Code I wrote-------------

def trump_tweet(text) :
    # Implement the Trump_twit() function according to the given rule.
    # Please erase the pass and write the code.
    words = text.split()

    Hashtag, Mention, Others = [],[],[]
    for word in words:
        if word.startswith('#'):
            plain_word=word[1:]
            Hashtag.append(plain_word)
        elif word.startswith('@'):
            plain_word=word[1:]
            Mention.append(plain_word)
        else :
            Others.append(word)
    return Hashtag, Mention, Others

print(trump_tweet(text))



# Don't modify the bottom part!
# Code that performs input and output.
t = input()
trump_tweet(t)

----------------------------------------------------

instructions
The Trump_tweet function divides text into nnn strings based on spaces. Categorize each divided string according to the rules below.

When each string starts with '#', it is classified as 'Hashtag' and stored in the list.
When each string starts with '@', it is classified as 'Mention' and stored in the list.
Otherwise, it is grouped separately and stored in the list.
Use the print function so that the list of each classified is printed as shown in the format specified below.

If you run the code I wrote,

Traceback (most recent call last):
  File "main.py", line 18, in <module>
    print(trump_tweet(text))
NameError: name 'text' is not defined

These errors are printed, but I don't know how to solve them even though I didn't define text.

I know that it's the foundation of the basics, but it's actually a liberal arts job, so I'm working on Python I don't have anything to touch, but the company ordered me to complete Python training, so I recently had a Chuseok holiday I took all the lectures on my daily schedule to work.

The short test that comes out at the end of a lecture was solved right away When I tried to write the code myself, my mind went blank and I was at a loss. Please help me.

It's not even my job, but I'm stressing you out and making you want to let go of everything It's crab Python. It would be nice to study hard if you have a lot of time, but complete it right away It's the expiration date, so I think I'm going to cry because I'm in a hurry, and I don't even dare to study alone ㅠ<

python

2022-09-20 15:03

1 Answers

You've probably solved this problem in math class.

When f(x) = 3x+9, find the value of f(4).

This is a question that you can solve and Python can solve. However,

When f(x) = 3x+9, find the value of f(y).

No one can solve this problem. I don't know what y is. But here

When f(x) = 3x+9 and y=-7, find the value of f(y).

You can solve it if you can solve this.

Now let's read the error of your code.

NameError: name 'text' is not defined

A name that Python doesn't know text appears, so they can't solve the problem. I guess we asked you to find the value of f(y) instead of f(4)! If you put the value directly into the place of the variable in the function, or if you use a variable with a value, can the function be executed?

print (trump_twet ("Enter any string")
  text 664 : "no strings or enter"
print(trump_tweet(text664))

I don't know because I haven't tried it, but try it yourself!

Is Python about to become the visual basic of the 21st century? I'd like to offer you my consolation.


2022-09-20 15:03

If you have any answers or tips


© 2022 pinfo. All rights reserved.