\n",
"#### and it happens that `(gender == 'Female)` is false, then the entire expression must be false. (Why?) In that case, Python doesn't bother to evaluate `(age >= 65)`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Similarly, when when Python evaluates the expression \n",
"####
`(semester_average >= 90) or (final_exam >= 90)`
\n",
"#### and it happens that `(semester_average >= 90)` is true, then the entire expression must be true. (Why?) In that case, Python doesn't bother to evaluate `(final_exam >= 90)`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### **TIP:** In `and` expressions, make put the part most likely to be false at the left. In `or` expressions, make the part most likely to be true at the left. These tricks can speed your program execution."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### **EXERCISE:** Given:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"i = 1\n",
"j = 2\n",
"k = 3\n",
"m = 2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### What does each of the following conditions display? "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"(i >= 1) and (j < 4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"(m <= 99) and (k < m)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"(j >= i) or (k == m)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"(k + m < j) or (3 - j >= k)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"not (k > m)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"##########################################################################\n",
"# (C) Copyright 2019 by Deitel & Associates, Inc. and #\n",
"# Pearson Education, Inc. All Rights Reserved. #\n",
"# #\n",
"# DISCLAIMER: The authors and publisher of this book have used their #\n",
"# best efforts in preparing the book. These efforts include the #\n",
"# development, research, and testing of the theories and programs #\n",
"# to determine their effectiveness. The authors and publisher make #\n",
"# no warranty of any kind, expressed or implied, with regard to these #\n",
"# programs or to the documentation contained in these books. The authors #\n",
"# and publisher shall not be liable in any event for incidental or #\n",
"# consequential damages in connection with, or arising out of, the #\n",
"# furnishing, performance, or use of these programs. #\n",
"##########################################################################\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Additional material (C) Copyright 2023 by Ronald Mak"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 4
}