2014-11-23 80 views
0

我有這個簡單的Python代碼,當我運行它時會引發錯誤。我不確定是什麼原因造成的,有人可以幫助解決一些問題嗎?在簡單的Python代碼中使用鍵盤輸入的語法錯誤

這裏是我的代碼文件test.py:

name = input("What's your name? ") 
print("You are great" + name + "!") 
age = input("Your age? ") 
print("you look great at" + str(age)) 

,這裏是錯誤:

>>> 
What's your name? kiran 

Traceback (most recent call last): 
    File "C:\Users\Sunshine\Desktop\test.py", line 1, in <module> 
    name = input("What's your name? ") 
    File "<string>", line 1, in <module> 
NameError: name 'kiran' is not defined 
>>> 

回答

1

,如果您使用Python 2.7獲得一個字符串從用戶輸入的正確方法使用方法raw_input(「」),輸入(「」)是python 3.