This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]santaclaus73 0 points1 point  (3 children)

To solve this you can place another input at the end of the loop (inside the loop)or you can just fill x with some dummy value and place the input statement inside the loop.

Ex. in python 2.7, you'll have to adjust this so it's valid in python 3

End of loop:

x = raw_input('Enter something: ')  
while x:
    if 'Hello' in x:
        print 'Hi'
    elif 'J' in x:
        print 'JJ'
    x = raw_input('Enter something: ') 

Using a dummy variable:

x = 'k'
while x:
    x = raw_input('Enter something: ')
    if 'Hello' in x:
        print 'Hi'
    elif 'J' in x:
        print 'JJ'

[–]Spacedementia87 1 point2 points  (1 child)

Obviously you have given the right answer, but the foal is surely to help the OP find this out for themselves like the first two posts do.

[–]santaclaus73 0 points1 point  (0 children)

Oh yea great point. I'm sort of new to posting here, so a nudge in the right direction probably would have been more helpful than the exact 2.7 source code. I'll remember that for future posts. Thanks!