2.4 Making Decisions
Now we know the chatbot can handle each question as a string. We also know that we want the chatbot’s answer to depend on the first word in the sentence. So, the chatbot needs some way to determine which word starts the question the user is asking. To do that, we can use Boolean expressions and a selection statement.
2.4.1 Boolean Expressions
A Boolean expression compares values of objects. The result is one of the two Boolean data values: True or False. These Boolean values are another primitive type in Python.
The easiest type of Boolean expression compares the results of two expressions. To make this comparison, we use operators you might recognize from mathematics: equality operators to compare if two values are equal, ...
Get Python Programming in Context, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.