[Solved] how to make loop on list inside if condition [closed]


Did you mean to hoist the input() in front of the loop?

mylist = ['good', 'great', 'fantastic', 'fine']

q = input('how are you?')
for word in mylist:
    if q == 'Im ' + word:
        print('Have a nice day')
        break
else:
    print('Sorry for that')

Example sessions:

how are you?Im good
Have a nice day

how are you?Im great
Have a nice day

how are you?Im fantastic
Have a nice day

how are you?Im fine
Have a nice day

how are you?im fine
Sorry for that

how are you?foo
Sorry for that

11

solved how to make loop on list inside if condition [closed]