wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

CSC40/40A - Lesson 4

Total questions: 10

Worksheet time: 7mins

Name
Class
Date
1.

Which of the following statements is used to perform the below task?

"Check if the sum is not equal to 100 or less than 80"

a)

if sum != 100 || sum < 80

b)

if sum != 100 && < 80

c)

if sum != 100 && sum < 80

d)

if sum != 100 || < 80

2.

Which of the following statements is used to perform the below task?

"Check if the sum is equal to 100 and less than 80"

a)

if sum == 100 || sum < 80

b)

if sum == 100 && < 80

c)

if sum == 100 && sum < 80

d)

if sum == 100 || < 80

3.

It results in true only if two statements are true:

a)

OR

b)

AND

c)

NOT

d)

Boolean

4.

It results in true only if one or both operands are true:

a)

OR

b)

AND

c)

NOT

d)

Boolean

5.

It results in true if the value is false, and vice versa.

a)

AND

b)

OR

c)

NOT

d)

Boolean

6.

Which of the following represents Logical Operator AND in Swift?

a)

!

b)

||

c)

&

d)

&&

7.

Which of the following represents Logical Operator OR in Swift?

a)

!

b)

||

c)

&

d)

&&

8.

Which of the following represents Logical Operator NOT in Swift?

a)

!

b)

||

c)

&

d)

&&

9.

Write and use a function collectGemCondition() to move a character forward twice and check if the path is blocked. If the path is blocked and there is a gem, collect the gem, turn left once, then move forward once.

What of the following is correct according to above description:

a)

moveForward()

moveForward()

if isBlocked && isOnGem {

collectGem()

}

turnLeft()

moveForward()

b)

func collectGemCondition()

{

moveForward()

moveForward()

if isBlocked && isOnGem {

collectGem()

}

turnLeft()

moveForward()

}

c)

func collectGemCondition()

{

moveForward()

moveForward()

if isBlocked {

if isOnGem {

collectGem()

turnLeft()

moveForward()

}

}


}

d)

moveForward()

moveForward()

if isBlocked {

if isOnGem {

collectGem()

turnLeft()

moveForward()

}

}

10.

Which of the following represents a symbol that connects two or more Booleans to make conditional decisions more specific and “and,” “or,” and “not” are example of it?

a)

Relational operator

b)

Comparison operator

c)

Mathematical operator

d)

Logical operator