Boolean operators Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

AND operator

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

OR operator

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

NOT operator

A

used to reverse the logical state of the other operators

if NOT (number1 == 3 OR number2 == 6) then
    result = true
endif
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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
A

The output will be “Conditions not met.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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

A

if (cost >= 10 AND cost <= 20) AND (type = “European” OR type = “Asian”) AND distance <= 10/AND NOT distance >10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly