我有一个我希望运行的完整工作程序。它在我朋友的笔记本电脑上执行,但不是我的,(我已将其保存到我的文档文件夹中)以下是该程序:
def DigitCount(n):
#how many decimal digits in integer 'n'
if n<0:
n=-n
digitCount=1
powerOfTen=10
while powerOfTen<=n:
digitCount+=1
powerOfTen*=10
return digitCount
但我一直收到以下错误:
>>> DigitCount(100)
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
DigitCount(100)
NameError: name 'DigitCount' is not defined
答案 0 :(得分:2)
等等,您是说要从命令行执行以下操作吗?
$ python DigitCount.py
$ python
>>> DigitCount(100)
那不会奏效。你必须这样做:
$ python
>>> import DigitCount
>>> DigitCount.DigitCount(100)