我是python的新手,我在codecademy上完成了这个挑战。
def spam():
eggs = 12
return eggs
print spam()
这适用于codecademy,但如果我把它放在IDLE中并运行它,我会收到一条错误,说错误的语法。所以我对正在发生的事情感到有些不满。任何人都可以提供帮助。
答案 0 :(得分:2)
IDLE最有可能使用Python 3运行它,其中print()是一个函数。以下代码应该修复它。
def spam():
eggs = 12
return eggs
print(spam())
答案 1 :(得分:1)
你必须为Python 3.x运行IDLE,其中print
不再是一个语句而是一个函数。因此,您需要将其称为:
def spam():
eggs = 12
return eggs
print(spam())
您的代码在CodeAcademy中工作,因为他们使用的是Python 2.x。