The 'in' operator and strings - Answers
Q1.
print('o' in 'mouse')
print('k' in 'rat')
print('pen' in 'open room')
print('pencil' in 'open room')
Q2.
print('o' not in 'mouse')
print('k' not in 'rat')
print('pen' not in 'open room')
print('pencil' not in 'open room')
Q3. Get the code working:
def common(firstWord, secondWord):
for letter in firstWord:
if letter in secondWord:
print(letter)
common('alphabet', 'tablet')
print('\n\n')
common('mississippi', 'miss')
Q4.
def common(firstWord, secondWord):
foundAlready=''
for letter in firstWord:
if letter in secondWord:
if letter not in foundAlready:
print(letter)
foundAlready = foundAlready + letter
common('alphabet', 'tablet')
print('\n\n')
common('mississippi', 'miss')