1

Im trying to make it so that even after I give the input to the "enter a command", the code will bring me back to the option to give input after displaying what the last input was. For example i would like it to display the "enter a command" prompt continually after previously done. Is there a way to loop the code back without it ever ending?

c1 = "p"
c2 = "d"
c3 = "t"

command = ""
while command != c1:
    print("Enter a command: ")
    print ("(P)profile / (D)data ")
    command = input()
    if command == c1 or command == c2:
        print ("loading...")

        time.sleep(3)

        if command == c1:
            print ("User: Student")
        if command == c2:
            print ("ID: 111111111")

        time.sleep(1)  

    print ("Enter a command: ")
    print ("(P)profile / (D)data ")
    command = input()

1 Answer 1

1

Put everything in a while True loop and remove the last 3 lines where you are printing and asking for input (since you're already asking for the input at the beginning) This should work:

c1 = "p"
c2 = "d"
c3 = "t"

while True:
    print("Enter a command: ")
    print ("(P)profile / (D)data ")

    command = input()
    if command == c1 or command == c2:
        print ("loading...")

        time.sleep(3)

        if command == c1:
            print ("User: Student")
        if command == c2:
            print ("ID: 111111111")

        time.sleep(1)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.