Difference between revisions of "CSC103: DT's Notes 1"
Line 116: | Line 116: | ||
|} | |} | ||
− | Let's keep our alarm example and think of how to program an alarm so that we can spend the morning in bed and not get up early on Saturdays and Sundays. We could have Statement ''a'' be "Today is Saturday", and Statement ''b'' be | + | Let's keep our alarm example and think of how to program an alarm so that we can spend the morning in bed and not get up early on Saturdays and Sundays. We could have Statement ''a'' be "Today is Saturday", and Statement ''b'' be "Today is Sunday". The boolean expression that will allow us to enjoy a morning in bed on weekends is ''a'' '''or''' ''b''. We can make our decision by saying: "if ''a'' '''or''' ''b'', we can stay in bed." On Saturdays, ''a'' is true, and the whole expression is true. On Sundays, ''b'' is true, and we can also stay in bed. On any other day, both ''a'' and ''b'' are false, and '''or'''-ing them together yields false, and we'd better get up early! |
+ | This all should start sounding familiar and "logical" by now. In fact, we use the same logic when searching for information on the Web, or at the library. For example, assume we are interested in searching for information about how to write a ''class construct'' in the language ''Python''. You could try to enter '''Python class''', which most search engine will internally translate as a search for "Python '''and''' class''. Very likely you might find that the results include references to python the animal, not the programming language. So to prevent this from happening we can specify our search as ''python and class and (not snake)''. | ||
+ | Back to the alarm example. Assume that we have the same ''a'' and ''b'' boolean variables as previously, on that is true on Saturdays only and one that is true on Sundays only. How could we make this alarm go off for any weekday and not on weekends? We could simply say that we want the opposite of the alarm we had to see if we can stay in bed on weekends. So that would be '''not''' ( ''a'' '''or''' ''b'' ). | ||
Revision as of 21:44, 30 January 2012
--© D. Thiebaut 08:10, 30 January 2012 (EST)