我有一个名为lab01.py的python文件,它包含两个函数
def both_positive(a, b):
return a > 0 and b > 0
def sum_digits(x):
"""
Sum all the digits of x.
"""
ans = 0
num = str(x)
for ele in num:
ans += eval(ele)
return ans
我需要在Git Bash中打印出sum_digits(x)函数的输出。这是我输入的命令行
$ cd ~/desktop/programming/lab01
$ python -c 'import lab01; print lab01.sum_digits(10)'
尝试将括号添加到打印函数:
不带括号的语法适用于Python2,如果计算机上安装了Python3,那么Git Bash仿真器应该运行Python3
在Python3中,Python2的print语句被替换为一个函数(因此是括号)。所以您需要使用
print()
编辑:另外,如果这是您用于lab01.py文件的代码,那么您的返回似乎在功能块之外
相关问题 更多 >
编程相关推荐