2017-04-20 2 views
-3

Ich versuche, eine Art Terminal Klon in Python zu machen (nur um die Macht von wenn sonst, und Elif Statments testen) Ich möchte es so machen, nachdem der Benutzer etwas in das Terminal eingibt und was auch immer diese Eingabe erledigt, es geht dahin zurück, wo Sie etwas eingeben können. So kann sagen, die BenutzereingabenPython Programm Loop

‚help‘

das Hilfe-Menü erscheint, dann wird der Terminal-Eingang „Terminal ~~ $“ erscheint wieder für sie in etwas anderes zu geben.

oder wenn der Benutzer Typen in

'waejhgiuoahweioug'

den Anschluss heißt es: 'Invalid Input' ich will es dann zurück zum Terminal-Eingang .. ("Terminal ~~ $") ich habe während Schleifen versucht, aber die Du scheinst nicht zu arbeiten. Hoffentlich macht das Sinn. Hier ist mein Code so weit (ich habe nur tkinter so kann ich die mainloop tun() Ich versuche nicht, ein Fenster für das Terminal zu machen (obwohl das wäre cool)!):

# Import wait settings and tkinter... we only need tkinter for the mainloop() setting, so the game doesn't close when it's finished # 
import time 
from tkinter import * 

print("Terminal V.1.0 Alpha") 
print("Type help for assistance with the terminal") 

# Input a command into the terminal! # 
terminalInput = input("Terminal~~$ ") 

# The inputs the terminal accepts # 

if terminalInput == "help": 
    time.sleep(1) 
    print("HELP") 
    print("Type: 'text = your_text' to make the terminal speak!") 
    terminalInput = input("Terminal~~$ ") 
    if terminalInput == "text = " + terminalInput: 
     print("Terminal:\\" + terminalInput) 

# Every input that the terminal does not accept # 
else: 
    print("Invalid Input: " + terminalInput) 

master = Tk() 
+0

Also, was genau ist das Problem mit einer Schleife um diese? Was ist dein Versuch bisher? Und wofür brauchst du 'tkinter'? –

+0

eine while-Schleife verwenden tut dies: –

+0

eine while-Schleife verwenden, funktioniert aber dies: Klemme V.1.0 Aplha Art Hilfe für die Unterstützung bei der Terminal Klemme ~~ $ lol Invalid Input: lol Invalid Input: lol ungültige Eingabe: lol Invalid Input: lol Invalid Input: lol Invalid Input: lol Invalid Input: lol Invalid Input: lol Invalid Input: lol Invalid Input: lol Invalid Input: lol Invalid Input: lol unendlich .... –

Antwort

0

Versuchen Sie folgendes:

while True: 
    # Input a command into the terminal! # 
    terminalInput = input("Terminal~~$ ") 

    # Indent rest of code so it's in the while block 
+0

dank Ihnen beiden. Du wirst im Abspann sein, wenn ich das zu meinem GitHub hinzufüge! –

+0

es funktioniert! Vielen Dank! –

0

Eine einfache While-Schleife kann dazu beitragen, dass das Programm läuft. Hier

ist der Code:

import time 

def help_loop(): 

    while True: 
      try: 
       print("Terminal V.1.0 Alpha") 
       print("Type help for assistance with the terminal") 

       # Input a command into the terminal! # 
       terminalInput = input("Terminal~~$ ") 

       print("Input: " + terminalInput) 

       if terminalInput.lower() == "help": 
        print("HELP") 
        print("Type: 'text = your_text' to make the terminal speak!") 
        try: 
         terminalInput = input("Terminal~~$ ") 
         if terminalInput == "text = " + terminalInput: 
          print("Terminal:\\" + terminalInput) 

        except Exception as ex: 
         print("Invalid Input: " + terminalInput) 
      except Exception as ex: 
       print("Invalid Input: " + terminalInput) 

def main(): 

    help_loop() 

if __name__ == '__main__': 
    main() 
0

Dank alle für die Hilfe! Hier ist, was ich bisher habe! Probieren Sie es bitte aus!

#Looking under the hood I see. Unless you know how to read Python, there are no secrets here ;)# 

# Import wait settings # 
import time 

print("Terminal V.1.5 Alpha") 
print("Type 'help' for assistance with the terminal.") 

# Loop # 
while True: 
    # Input a command into the terminal! # 
    terminalInput = input("Terminal~~$ ") 

    # The inputs the terminal accepts # 

    # HELP # 
    if terminalInput == "help": 
     time.sleep(0.5) 
     print(".") 
     print("#~~Help~~#") 
     print("Type: 'cred' for the credits to this program") 
     print("Type: 'errorcodes' for common errors in the terminal") 
     print(".") 

    # CREDITS # 
    if terminalInput == "cred": 
     time.sleep(0.5) 
     print(".") 
     print("#~~Credits~~#") 
     print("Elmar Peise/David Cullen: Help with looping the program!") 
     print(".") 

    # ADMIN CODE # 
    if terminalInput == "adminpass123": 
     time.sleep(0.5) 
     print(".") 
     print("Welcome Administrator") 
     print(".") 

    # ERROR CODES # 
    if terminalInput == "errorcodes": 
     time.sleep(0.5) 
     print(".") 
     print(".") 
     print("1. ERROR CODE 404:") 
     print("An invalid input has been entered to the terminal. (Such as 'blablabla' or 'jg48923qj09')") 
     print("FIX:") 
     print("Make sure your spelling is correct. This is a common mistake. Or try entering a valid input. 'help' can get you started on inputs") 
     print(".") 

    # ELSE # 
    else: 
     time.sleep(0.5) 
     print(".") 
     print("ERRORCODE 404: Invalid Input, Type 'errorcodes' for more info.") 
     print(".") 
+0

stackoverflow ist nicht für Diskussionen. Bitte posten Sie keine Kommentare im Antwortbereich. –