" print(f'the letter \"{letter}\" is in the word \"{word}\"!')\n",
" else:\n",
" print(f'the letter \"{letter}\" is NOT in the word \"{word}\"!')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# check if a word is in a sentence\n",
"sentences = [\n",
" 'Software and language are intrinsically related, since software may process language, and is constructed in language.', \n",
" 'Yet language means different things in the context of computing: formal languages in which algorithms are expressed and software is implemented, and in so-called “natural” spoken languages.', \n",
" 'There are at least two layers of formal language in software: programming language in which the software is written, and the language implemented within the software as its symbolic controls.'\n",
"]\n",
"word = 'programming'\n",
"for sentence in sentences:\n",
" print('---')\n",
" if word in sentence:\n",
" print(f'the word \"{word}\" is in the sentence \"{sentence}\"!')\n",
" else:\n",
" print(f'the word \"{word}\" is NOT in the sentence \"{sentence}\"!')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# check if a word ends with \"ing\"\n",
"words = ['hello', 'language', 'weaving']\n",
"for word in words:\n",
" if word.endswith('ing'):\n",
" print(f'YES, the word \"{word}\" ends with \"-ing\"!')\n",
" else:\n",
" print(f'NO, the word \"{word}\" DOES NOT end with \"-ing\"!')"