pythonidle不会运行我以前保存并重新打开的cod

2024-10-02 22:34:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我最近开始学习python,当我关闭空闲并保存我的工作时。 当我回到它打开空闲和打开我保存的工作,并去测试它与f5运行模块,模块不产生和错误代码,甚至不打印出我简单的打印命令。如果我用几个命令快速输入一个新的项目,它工作得很好,它只是我以前保存的工作。。。在

有人有什么想法吗?在

我的操作系统是Windows7Home,知道我以前安装过3.2和2.6可能会有帮助

编辑:原来我的代码也不会通过python在命令中运行我的代码看起来不错,但会在这里发布:

import random
import time

Coin = 100
Health = 100
PCName = ()

def displayIntro():
    print "You wake, bound to the cell wall by shackles..."

Tags: 模块项目代码import命令编辑timerandom
2条回答

您编写的代码是python2,而不是3。下面是如何调用print():

    print("You wake, bound to the cell wall by shackles...")

执行此模块不会做任何事情。您只需进行一些导入,定义一些全局变量,然后定义一个函数。如果要查看打印的内容,必须调用函数:

import random
import time

Coin = 100
Health = 100
PCName = ()

def displayIntro():
    print "You wake, bound to the cell wall by shackles..."

displayIntro() # when the interpreter reaches this line, a warm welcome will be printed

相关问题 更多 >