0

i have the following python script:

import sys 

text = ""
while 1:
    while 1:
       c = sys.stdin.read(1)
       text = text + c
       if c == '\n':
           break

    print("Input: %s" % text)
    print (text)
    print ( text == 'Exit')
    print(text)
    if(text is "Exit"):
        print('you have exited')
        break
    text = ''

The intent is to keep on printing words which user inputs, till the word he inputs is 'Exit'. But when i enter the word 'Exit' it doesn't break out of the outer while loop. Any idea why?

Mazdak
  • 105,000
  • 18
  • 159
  • 188
ACD
  • 1
  • May I ask why you're using `sys.stdin.read(1)` instead of just `input()`? – TigerhawkT3 Jul 17 '15 at 22:07
  • This doesn't need to be refactored into a function as suggested into the linked question; it simply has an unnecessary loop. – TigerhawkT3 Jul 17 '15 at 22:12
  • right, i can go along with the input() method. I can also achieve the end result by using a single loop. But in the code i have have given i am noticing something weird. For the three print statements in the middle i.e. print (text) print ( text == 'Exit') print(text). I am getting the out put as Exit False Exit. So i was wondering if the code is wrong or maybe i am missing some trivial point. – ACD Jul 17 '15 at 22:59

0 Answers0