I'm trying to make a program in Python that while executing a loop loop, some command is waiting for an input condition while the loop is executed.
For example, a program that prints on the screen numbers, in ascending order and every 1 second, from zero while waiting for the user to enter a string "quits". When this string is read, the loop is interrupted and stops printing the numbers on the screen.
I tried to do this, but it did not work:
#-*- coding: utf-8 -*-
import time
i = 0
mensagem = 0
while mensagem!='terminar':
mensagem = str(raw_input())
if mensagem=='terminar':
print "encerrado"
else:
print i
time.sleep(1)
i+=1