user3015794
user3015794

Reputation: 7

Python program keeps printing "quit" when I just want it to end

the program below will not stop printing "quit"

myvar = str("")
while myvar.lower() != "quit":
    myvar = raw_input()
    print myvar 

Thanks

Upvotes: 1

Views: 93

Answers (2)

afkfurion
afkfurion

Reputation: 2865

Just change the order.

myvar = raw_input()
while myvar.lower() != "quit":
    print myvar 
    myvar = raw_input()

Upvotes: 2

user2555451
user2555451

Reputation:

I would use a while True: loop and then break it when myvar.lower() == "quit":

# Loop continuously
while True:   
    # Get the input                  
    myvar = raw_input()
    # When converted to lowercase, if the input equals "quit"...
    if myvar.lower() == "quit":
        # ...break the loop
        break
    # If we get here, then myvar.lower() != "quit"
    # So, print the input
    print myvar 

Upvotes: 3

Related Questions