繁体   English   中英

Python(spyder)-未定义名称“ debugfile”

[英]Python (spyder) - name 'debugfile' is not defined

我是编程的初学者,我需要在大学课程中学习。 我正在使用的程序是Spyder(昨晚下载),我必须在“ python”中进行编码。 我已经下载了所需的版本,但似乎无法运行简单的代码。

# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""

import math

def circleAreaFromDiameter(d):
    """takes a float d and returns the area of a cirlce with diameter d.
    """
    Area = math.pi * d**2/4.0
    return Area

print circleAreaFromDiameter(1)

最后一行“ print circleAreaFromDiameter(1)”在其侧面有一个感叹号,表示这是无效的语法。 我不明白为什么,但是我不认为这是我的问题。

当我按下“运行文件”或“调试文件”时,它说:

追溯(最近一次呼叫最近):NameError中文件“”的第1行:未定义名称“ runfile”

要么

追溯(最近一次呼叫最近):NameError中文件“”的第1行:未定义名称“ debugfile”

我真的很感谢您的帮助。

清理换行符,我认为它应该运行良好。 这种形式对我来说应该是:

import math

def circleAreaFromDiameter(d):
    """takes a float d and returns the area of a cirlce with diameter d. """
    area = math.pi * d**2/4.0
    return area

print circleAreaFromDiameter(1)

问题是将区域分配与块引号(三重引号的字符串)粘贴在同一行上。

如果您已安装Python 3,则现在的打印语法为

print (circleAreaFromDiameter(1))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM