Это продолжение моего предыдущего вопроса , с более подробной информацией.(Форматирование должно быть лучше, поскольку я сейчас на компьютере!)
Поэтому я пытаюсь создать игру на 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!