Comparison operators Flashcards

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

Comparison operators

A

Used to compare different items of data

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

==

A

equal to

Checks if two values are equal
Two equal signs distinguish it from assigning a value to a variable

e.g. if length == width then

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

!=

A

Not equal to

Checks of two values are not equal to each other

e.g. if length != width then

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

Less than

Checks if one value is less than another

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

<=

A

Less than or equal to

Checks if one value is equal or less than another

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

>

A

Greater than

Checks if one value is greater than another

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

> =

A

Greater than or equal to

Checks if one value is equal to or greater than another

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

Comparing strings

A

These operators can also be used with strings

They are compared alphabetically

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

Write an algorithm in pseudocode which asks the user to enter a number between 1 and 10 and then states if it is higher, lower, or equal to 5. [4]

A
number = input("Enter a number between 1 and 10")
if number > 5 then
    print("Higher than 5.")
elseif number < 5 then 
    print("Lower than 5.")
else
    print("You entered 5")
endif
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Write an algorithm in pseudocode which asks the user to enter a number between 1 and 10 and then states if it is higher, lower, or equal to 5. [4]

A
number = input("Enter a number between 1 and 10")
if number > 5 then
    print("Higher than 5.")
elseif number < 5 then 
    print("Lower than 5.")
else
    print("You entered 5")
endif
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Write an algorithm, in pseudocode, that allows a user to enter two values as value1 and value2 and which will switch the values, if necessary, so that they are in ascending order [2]

A
value1 = input()
value2 = input()
if value1 < value2 then
    temp = value1
    value1 = value2
    value2 = temp
endif
How well did you know this?
1
Not at all
2
3
4
5
Perfectly