Watch the video and take notes, pay attention to how to use logic operators in boolean expressions to improve your statements.
Run and walk through the example (in code window).
Read the task and write code to solve.
Make a note of successful code in your book.
Answer questions in your book
Watch the video and create notes in order to be able able to apply the knowledge given.
You would use logic operators when creating Boolean expressions to use with selection (if) and iteration (loops)
AND 1 == 1 and "a" == "a" is True Returns True if both statements are True
OR 1 == 2 or "a" == "a" is True Returns True if one of the statements is True
NOT not(1 == 1 and "a" == "a") is False Reverse the result, returns False if the result is True
# Code example (Boolean expression)
age = int(input("Enter your age :"))
if age > 0 and age <= 10:
print("You should attend primary school")
elif age >= 11 and age <= 16:
print("You should attend secondary school")
elif age >= 17 and age <= 19:
print("You should attend college")
else:
print("You should attend university")
Applying your knowledge of Boolean operators and expressions, write a program that will ask a user to input their height in metres (1.1), if their height is between the values 1.20 and 2.00 output a message that states they are allowed to ride the rollercoaster, any value outside the range output a message that states they will not be able to ride the coaster.
input users height
if value is in the range 1.20 and 2.00 output can ride on screen
values outside of the range will output cannot ride on screen
eight = float (input("Enter your height in metres"))
if height >= 1.20 and height <2.00:
print("You can ride the rollercoaster")
else:
print("You cannot ride the roller-coaster")
Write 2 AND Boolean logic expressions that evaluate as True
Write 2 AND Boolean logic expressions that evaluate as False
Write a sentence you can refer to when using AND logic, your sentence should describe how they work.
Write 2 OR Boolean logic expressions that evaluate as True
Write 2 OR Boolean logic expressions that evaluate as False
Write a sentence you can refer to when using OR logic, your sentence should describe how they work.
Write 2 NOT Boolean logic expressions that evaluate as True
Write 2 NOT Boolean logic expressions that evaluate as False
Write a sentence you can refer to when using NOT logic, your sentence should describe how they work.
Type your Boolean logic expression into python and run, it will display the answer.
3. Both need to be True for the whole expression/statement to be True
6. Either one or the other needs to be True for the expression to be True
9. Reverse the value of the given expression True is False and vice versa