这是我之前的问题的延续,有更多细节。(格式化应该更好,因为我现在在电脑上!)
所以我正在尝试用 Python 创建一个游戏,如果一个数字达到一定数量,你就会输掉。你试图控制这个数字,以防止它达到它不应该达到的数字。现在,我在之前的问题中有一个错误:
AttributeError:模块 'core temp' 没有属性 'ct'
但是,我对代码进行了一些修改,不再出现任何错误。但是,当我运行代码时,我制作的模块中的函数不会运行。
为了确保任何试图找出解决方案的人都拥有他们需要的所有资源,我将提供我所有的代码。
这是文件中的代码main.py
:
from termcolor import colored
from time import sleep as wait
import clear
from coretemp import ct, corestart
print(colored("Begin program", "blue"))
wait(1)
clear.clear()
def start():
while True:
while True:
cmd = str(input("Core> "))
if cmd == "help":
print(
"List of commands:\nhelp - Show a list of commands\ntemp - Show the current temperature of the core in °C\ninfo - Show core info\ncool - Show coolant control"
)
break
elif cmd == "temp":
if ct < 2000:
print(
colored("Core temperature: " + str(ct) + "°C",
"green"))
elif ct < 4000:
print(
colored("Core temperature: " + str(ct) + "°C",
"yellow"))
elif ct >= 3000:
print(
colored("Core temperature: " + str(ct) + "°C", "red"))
print("Welcome to SprinkleLaboratories Main Core System")
wait(1)
print(
"\nYou have been hired as the new core operator.\nYour job is to maintain the core, and to keep the temperature at a stable number. Or... you could see what happens if you don't..."
)
wait(3)
print("\nTo view available commands, use the \"help\" command!")
cont = input("Press enter to continue> ")
clear.clear()
start()
corestart(10)
这是文件中的代码clear.py
:
print("clear.py working")
def clear():
print("\n"*100)
这是文件中的代码coolant.py
:
from time import sleep as wait
print("coolant.py working")
coolam = 100
coolactive = False
def coolact():
print("Activating coolant...")
wait(2)
coolactive = True
print("Coolant activated. "+coolam+" coolant remaining.")
这是文件中的代码coretemp.py
:
from coolant import coolactive
from time import sleep as wait
print("coretemp.py working")
ct = 0
def corestart(st):
global ct
ct = st
while True:
if coolactive == False:
ct = ct + 1
print(ct)
wait(.3)
else:
ct = ct - 1
print(ct)
wait(1)
笔记:
文件中的一些代码不完整,所以有些事情现在看起来好像什么都不做
如果你想查看代码本身,这里有一个 repl.it 的链接: Core
笔记2:
对不起,如果事情的格式不正确,如果我在问题中做错了什么等等。我对在 Stackoverflow 上提问还很陌生!