'Zybooks 13.3.1 Challenge Activity
I am struggling on completing this zybook challenge activity and I don't know what else
Complete the if-else statement to print 'LOL means laughing out loud' if user_tweet contains 'LOL'.
Sample output with input: 'I was LOL during the whole movie!' LOL means laughing out loud.
Solution 1:[1]
What this is asking you to do is print "LOL means laughing out loud" if LOL is in the tweet (if 'LOL' in user_tweet:
).
If the tweet does not have LOL (else:
), print 'No abbreviation.'
This gives you the if-else statement:
if 'LOL' in user_tweet:
print('LOL means laughing out loud.')
else:
print('No abbreviation.')
Solution 2:[2]
enter code here
user_tweet = input()
if(user_tweet.find('LOL') != -1):
print('LOL means laughing out loud.')
else:
print('No abbreviation.')
Using the find function works as well. The find function is searching user_tweet for string placement index != (not equal) to -1. The find function returns the index of the first occurrence of item x in the string, else returns -1.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Tomerikoo |
Solution 2 | hawkisberg |