0
我目前正在使用Codecademy讓我的腳溼透Python。我學習速度非常快,已經安裝並正在使用Pyscripter在Codecademy課程中創建自己的程序。當我將Codecademy的代碼複製並粘貼到Pyscripter並嘗試運行它時,通常會在Codecademys網站上完美運行時發生錯誤。是否有不同的Python版本?或者是Codecademy沒有教導適當的基礎?我已經包含了一個代碼示例和我收到的錯誤。從Pyscripter接收Codecademy Python和Pyscripter給出錯誤消息
def power(base, exponent): # Add your parameters here!
result = base**exponent
print "%d to the power of %d is %d." % (base, exponent, result)
power(37, 4) # Add your arguments here!
錯誤:消息文件名線位置
的SyntaxError
無效的語法(13行)13 40
又如:
from datetime import datetime
now = datetime.now()
print ('%s/%s/%s') % (now.year, now.month, now.day)
錯誤:消息文件名線位置
回溯
TypeError:不支持的操作數類型爲%:'NoneType'和'元組'
當我使用%s和%時,似乎有一段時間。
任何澄清將不勝感激。
那麼接下來需要什麼功能
print
之間的差別中心做糾正它嗎?我嘗試輸入'>>> from datetime import datetime >>> now = datetime.now() >>> >>> print('%s /%s /%s')%(now.year,now .month,now.day) %s /%s /%s',它仍然給我一個錯誤。 –@ user3342332 - 查看我編輯的python 3打印語法,或查看此鏈接:http://docs.python.org/3.1/library/string.html#format-string-syntax –
謝謝,我明白了現在! –