tTheLastDinosaur
tTheLastDinosaur

Reputation: 37

def function python - Help me with syntax

I am a python newbie, learning the basics now. I tried the following def function.But it indicates an error. Can somebody tell me where I make the mistakes in the syntax.

(I wrote it with the proper indentation. but the Stakoverflow window does not indicate as I paste it)

# This will test the reverse function of the program

def rev(text) :
    text = input()
    return text [::-1]

print("Please Enter a word")
input()
rev(text)

input() # This is to avoid the screen closing immediately after executing the
        # program

Upvotes: 1

Views: 159

Answers (1)

thefourtheye
thefourtheye

Reputation: 239473

You have to assign a value to a variable before using it.

print("Please Enter a word")
input()
rev(text)

You are using text here, but you havn't assigned any value to it. You might want to do like this

print("Please Enter a word")
text = input()
rev(text)

Now, input will read data from the user and it will be available with text

Suggestion 1: As @seaotternerd suggested in the comments, you don't need to print the message and read inputs, you can directly do,

input("Please Enter a word") 

Upvotes: 4

Related Questions