【发布时间】:2021-03-06 14:12:45
【问题描述】:
所以,基本上,我只是在编写代码,这样如果你写了一个游戏的名字,它就会打开它。
print('You can play games here!')
time.sleep(1.5)
print('Snake')
time.sleep(0.5)
print('Maze')
time.sleep(1.5)
print('Type the name of one of the games to open it!')
game = input()
if game == 'Snake':
import Snake
else:
if game == 'Maze':
import Maze
print('This Program Is Still In Development')
当我选择“Snake”时,它可以完美运行。但是当我选择“迷宫”时,它只是跳到print('This Program Is Still In Development') 部分。
有人可以帮忙吗?我在 MAC OS X 顺便说一句
编辑:如果我这样做elif,它不会改变。函数也没有。出于某种原因,唯一有效的游戏是 Snake。
编辑 2:奇怪的是,当我单独打开 Maze.py 时,它可以工作。怎么样?
【问题讨论】:
-
当您
import Maze时是否应该发生任何可见的事情? (顺便说一句,约定是在 Python 中使用小写的模块名称) -
import Maze 在终端中打开一个新游戏。比如,当我输入“迷宫”时,它应该会打开游戏
-
我认为您的程序不会跳过任何内容,只需检查
Maze模块的功能...顺便说一句,不知道是否只是 sn-p 但我看到那里有一些缩进泄漏 -
那我们能看到 Maze.py 模块吗?顺便说一句,
-
我建议在文件顶部导入所有模块并创建主要功能(例如
main()或run()),这样您就可以使用Maze.main()而不是import Maze。以这种方式检测导入问题会更容易,因为它们都会在开始时被调用
标签: python macos macos-catalina