python IDLE无法运行我之前保存并重新打开的代码
我最近开始学习Python,当我关闭IDLE并保存我的工作时,
当我回来打开IDLE并打开我保存的工作,想用F5运行模块测试时,模块没有产生任何错误代码,甚至连我简单的打印命令都没有输出。不过,如果我快速写一个新项目,输入几个命令就能正常工作,问题只出在我之前保存的工作上……
有没有人知道是什么原因?
我的操作系统是Windows 7家庭版,可能有用的是我之前安装过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..."
2 个回答
0
你写的代码是Python 2的,不是Python 3的。下面是你应该怎么使用print()函数的:
print("You wake, bound to the cell wall by shackles...")
2
运行这个模块不会有什么效果。你只是做了一些导入,定义了一些全局变量,还定义了一个函数。如果你想看到一些输出,你必须调用你的函数:
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