+ -
当前位置:首页 → 问答吧 → 新手请帮忙,谢谢

新手请帮忙,谢谢

时间:2011-03-04

来源:互联网

def factorial(x):      
if x == 0:         
return 1      
else:         
return x * factorial(x - 1)  
print factorial(6)

还有这么一段
def sayHello():
    print 'Hello World!' # block belonging to the function

sayHello()

运行时提示:SyntaxError: invalid syntax
是为什么?

作者: masaic117   发布时间: 2011-03-04

把完整的 error message 貼上來吧....

就這樣看沒什麼問題, 除非你用的是 3.0 以上, 你的 print 就有問題

作者: eookoo   发布时间: 2011-03-06

我也是刚学
我是 3.1版本的,刚刚编译了下,这样就有输出了
def factorial(x):      
    if x == 0:         
        return 1      
    else:         
        return x * factorial(x - 1)  
print (factorial(6))

第二个,也应该是print格式的问题

作者: werm520   发布时间: 2011-03-06

热门下载

更多