Boolean operators Flashcards
AND operator
ensures that the overall statement is true only if all of the individual statements are true
e.g.
If number1 == 3 AND number2 == 6 AND number3 == 10 then
result = true
endif
OR operator
ensures that the overall statement is true if any of the individual statements are true
e.g.
if number1 == 3 OR number2 == 6 then
result = true
endif
NOT operator
used to reverse the logical state of the other operators
if NOT (number1 == 3 OR number2 == 6) then result = true endif
State the output from this algorithm with these values. [1]
At the start of the algorithm X = 2, Y = 6 and Z = 9
if (X == 3 OR Y == 6) AND NOT (Z = 9) then print("Conditions are met.") else print("Conditions not met.") endif
The output will be “Conditions not met.”
A student is writing a program that will search data to find suitable restaurants. The cost of the me should be between £10 and £20. The type of food should be European or Asian and the restaurant should be no more than 10 miles away.
Complete the following algorithm by inserting the missing line. [3]
cost = input(“Please enter the cost of a meal.”)
type = input(“Please enter the type of food served.”)
distance = input(“Please enter the distance away of the restaurant.”)
…………………………………………………………………………..
print(“This restaurant is suitable.”)
else
print(“This restaurant is not suitable.”)
endif
if (cost >= 10 AND cost <= 20) AND (type = “European” OR type = “Asian”) AND distance <= 10/AND NOT distance >10