2013-02-24 54 views
0

想我的第一PROGRAMM與Python 3.3.0的Python 3.3.0錯誤

print ("cookies") 
x= input ("enter your name") 
print ("good day to you sir ") + x 

當我要開始我的PROGRAMM與F5它說

Traceback (most recent call last): 
    File "C:/Users/xxxx/Desktop/cookies.py", line 3, in <module> 
    print ("good day to you sir ") + input 
TypeError: unsupported operand type(s) for +: 'NoneType' and 'builtin_function_or_method' 

回答

1

打印值正確的方法是print ("hello", input)print ("hello" + input)

4
print ("good day to you sir ") + x 

print是在Python 3的函數,因此在括號屬於福nction。 print函數本身的返回值爲None,所以您實際上做的是None + x,這會引發您得到的錯誤。

你想要做的,而不是什麼是直接Concat的兩個字符串,括號內:

print("good day to you sir " + x) 

而且您的異常實際上是一個有點不同,但你仍然有print(..) + input(我想這是一個老)請注意,input是從用戶獲取數據的函數的參考,因此您實際上嘗試添加None和函數引用。

0

要打印的所有文本和變量必須位於打印功能的括號內。

所以不是:

print("good day to you sir ") + x 

這將是:

print("good day to you sir " + x) 

或者,你也可以使用,而不是加號的逗號自動給出一個空間:

print("good day to you sir", x) 

代碼的其他部分都很好。