0

実行したいコマンドを入力するように求める選択メニューを作成しました。and ステートメントを使用してこれをif行いましelifたが、コマンド (if ステートメント) が終了したら、どのコマンドかを尋ねる行に移動してもらいたいと思います。実行するコマンド。これが私が現時点で持っているコードです(今のところ、これを行うものは何もありません):

# 実行するコマンドを尋ねます。
word = input("どのコマンド? ")

# コマンドを実行します。

単語 == "情報" の場合:
    print("情報コマンド")

elif ワード == "置換":
    print("コマンドを置き換えます。")

elif ワード == "ping":
    print("Ping コマンド")

そうしないと:
    print("コマンドが見つかりません")

誰かが助けてくれたら最高です、ありがとう。

4

2 に答える 2

1

Sorry if this is too much, but you might want to consider putting it into a function to do something like this:

def main():
    # Asks which command you want to run.
    word = input("Which command? ").strip().lower()

    # Runs the command/s.

    if word == "info":
        print("Info command.")

    elif word == "replace":
        print("Replace command.")

    elif word == "ping":
        print("Ping command")

    elif word == "quit":
        return False

    else:
        print("Command not found")
    return True

while main():
    pass

This would be the same thing as while True then if something: break

于 2012-12-28T18:44:46.390 に答える
0

while True:コードをブロックにラップしてみてください。これにより、コードが無期限に繰り返されます。

さらに読むには、これを試してください

于 2012-12-28T18:40:40.663 に答える