-2
choice = 'yes'
while choice is 'yes':
    choice = input("Enter a value for choice : ")
    # when i input 'yes' from keyboard for choice, it falls to else block.
    if choice is 'yes':
        print("As expected")
        break
    else:
        print("Need Help !!!")

I have even tried to match with 'yes\r', as we press 'enter' after our input from keyboard, it still failed to match. Need some insight.

1 Answers1

1

The is keyword is a test for object identity while == is a value comparison. Thus, you needed to change your is to ==.

choice = 'yes'
while choice == 'yes':
    choice = input("Enter a value for choice : ")
    if choice == 'yes':
        print("As expected")
        break
    else:
        print("Need Help !!!")
peachykeen
  • 4,143
  • 4
  • 30
  • 49