2013-12-21 67 views
1

我是一个python新手,现在学习基础知识。我尝试了下面的def函数,但它表明一个错误。有人能告诉我我在语法中犯了什么错误吗?def function python - 帮我使用语法

(我用正确的缩进写的。但Stakoverflow窗口并不表示我粘贴)

# 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 

回答

4

你必须在使用之前将值分配给一个变量。

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

您使用text在这里,但你没有带分配给它的任何值。你可能想要做这样的

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

现在,input将读取用户数据,这将是可用text

建议1:作为@seaotternerd的意见建议,你不” t需要print消息和读取输入,你可以直接做,

input("Please Enter a word") 
+0

它也没有必要打印提示,然后分别调用input()。输入(“请输入一个单词”)将完成两个。 – seaotternerd

+0

@seaotternerd谢谢:)补充说,在答案:) – thefourtheye

相关问题