0

これは私の以前の質問の続きで、詳細があります。(今はコンピューターを使用しているので、フォーマットはより良いはずです!)

だから私は 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 で質問するのは初めてです。

4

1 に答える 1