Problem with flag or string?

Asked

Viewed 47 times

0

In this simple code the program should exit the loop when I type the word quit.

msg = 'Que lugar gostaria de visitar?'
active = True
while active == True:

Here the input is assigned to place and then to word Then check if word equals QUIT and should exit loop with flag to False. But what happens is that the loop keeps going to Else by printing QUIT

    place = input(msg)
    word = place.upper
    if word == 'QUIT':
        active = False
    else:
        print("Então vamos pra "+place+"!")

I don’t know what’s going on, I’ve tried breaking and the same thing happens

  • 2

    upper is a function, therefore needs to do place.upper()

  • Tip, you can simply use while True: to keep the loop and the command break to force the output of this instead of working with a single variable for flow control (makes things more obvious).

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.