wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Control Statements and Looping

Total questions: 99

Worksheet time: 1hrs 14mins

Name
Class
Date
1.

What is the output of the following loop:-

for l in 'Jhon':

if l == 'o':

pass

print(l, end=", ")

a)

J, h, n,

b)

J, h, o, n,

c)

Error

d)

None of the given Options

2.

What is the output of the following range() function?


for num in range(2,-5,-1):

print(num, end=", ")

a)

2, 1, 0

b)

2, 1, 0, -1, -2, -3, -4, -5

c)

2, 1, 0, -1, -2, -3, -4

d)

0

3.

Given the nested if-else below, what will be the value x when the code is executed successfully.

a)

0

b)

4

c)

2

d)

3

4.

Given the nested if-else structure below, what will be the value of x after code execution completes.

a)

2

b)

0

c)

3

d)

4

5.

What is the output of the following nested loop?

a)

10 Chair

10 Table

20 Chair

20 Table

b)

10 Chair

10 Table

6.

What is the value of x?

a)

101

b)

None of the given options, this is an infinite loop

c)

99

d)

100

7.

What is the output of the following if statement?

a)

False

b)

True

8.

What is the output of the following for loop and range() function?

a)

-2, -1, -3, -4

b)

-2, -1, 0, 1, 2, 3

c)

-2, -1, 0

d)

-2, -3, -4

9.

What is the value of the var after the for loop completes its execution?

a)

20

b)

21

c)

10

d)

30

10.

What is the value of x after the following nested for loop completes its execution?

a)

99

b)

90

c)

100

d)

0

11.

What is the output of the following nested loop?

a)

10

11

12

13

b)

11

13

12.

Select which is true for: (for loop).

Hint: (We use while loop when we want to perform a task indefinitely until a particular condition is met.)

a)

Python’s for loop used to iterates over the items of list, tuple, dictionary, set, or string.

b)

We use for loop when we want to perform a task indefinitely until a particular condition is met

c)

else clause of for loop is executed when the loop terminates abruptly

d)

else clause of for loop is executed when the loop terminates naturally

13.

In programming, what is iteration?

a)

The repetition of steps within a program

b)

The order in which instructions are carried out

c)

A decision point in a program

d)

Testing a program to make sure it works

14.
Which two statements are used to implement iteration?
a)
IF and WHILE
b)
ELSE and WHILE
c)
FOR and WHILE
d)
IF and ELSE
15.

FOR loops are

a)

loops which run an unknown number of times

b)

loops which run for a specific number of times

c)

the same as if statements

d)

not part of programming

16.

WHILE loops are

a)

loops which run an unknown number of times

b)

loops which run for a specific number of times

c)

the same as if statements

d)

not part of programming

17.

The result of this program:

Friday = False

if Friday:

print "Jeans day!"

else:

print "Uniform day"

a)

Jeans day

b)

Today is Friday

c)

Uniform day

d)

Not Friday

18.

What is the output?

a)

condition

b)

True

c)

Program has a syntax error.

d)

3 > 2

19.

What is the output?

a)

True

b)

False

c)

condition1

d)

condition2

20.

What is the output?

a)

more than 7

b)

more than 23

c)

spam

d)

7

21.

What is the output?

a)

250.0

b)

200.0

c)

300.0

d)

350.0

22.

What is the output?

a)

next

stop

b)

next

c)

stop

d)

syntax error - program doesn't work

23.

What is the output?

a)

3

b)

3

7

c)

3

5

7

d)

7

24.

What is the output?

a)

True

b)

NIL

c)

True

NIL

d)

True

NIL

NIL

25.

What is the output?

a)

level 3

b)

level 3

level 1

c)

level 3

level 1

NIL

d)

level 3

level 2

level 1

NIL

26.

What part of an if statement should be indented?

a)

All of it

b)

The statements within it

c)

the first line

d)

the lines within the brackets

27.

Given the nested if-else below, what will be the value x when the code is executed successfully.

a)

0

b)

4

c)

2

d)

3

28.

Given the nested if-else structure below, what will be the value of x after code execution completes.

a)

2

b)

0

c)

3

d)

4

29.

What is the output of the following if statement?

a)

False

b)

True

30.
Which is the correct syntax?
a)
has_dog = true
b)
has_dog = True
c)
has_dog = Treu
d)
HAS_DOG = tRue
31.
An if statement must evaluate to:
a)
Right or Wrong
b)
True
c)
True or False
d)
False
32.
This operator means that one value is the same as the other value
a)
==
b)
!=
c)
>
d)
<
33.

What is the result of the code:

team = Cowboys

if team = Cowboys:

print(Dallas is #1)

a)

Error

b)

Cowboys

c)

Team

d)

Dallas is #1

34.
What best defines an IF statement in python?
a)
Is an embedded string with a variable
b)
An IF statement checks to see if a statement is true or false and then does one of two things depending on the result.
35.
I am 71 years old! What will the output be?: IF you are 70 or older, say “You are aged to perfection!” ELIF you are exactly 50, say “Wow, you are half a century old!” ELSE say “You are a spring chicken!”
a)
“You are aged to perfection!”
b)
"Wow, you are half a century old!"
c)
"You are a spring chicken!"
36.
I am 18 years old! What will the output be?: IF you are 70 or older, say “You are aged to perfection!” ELIF you are exactly 50, say “Wow, you are half a century old!” ELSE say “You are a spring chicken!”
a)
"You are aged to perfection"
b)
"Wow, you are half a century old!"
c)
"You are spring chicken!"
37.
The second part of if, that is executed when the condition is false
a)
if
b)
else
c)
for
d)
input
38.
Which statement will check to see if a is equal to b?
a)
if a == b
b)
if a = b:
c)
if a != b:
d)
if a == b:
39.

What is the output?

a)

more than 7

b)

more than 23

c)

spam

d)

7

40.

Pieces of code that only run "under certain conditions":

a)

conditional statements

b)

control flow statments

c)

syntax

d)

variables

41.

Which symbol means "not equal to"?

a)

==

b)

<=

c)

>=

d)

!=

42.

Which character must be at the end of the line for if?

a)

:

b)

;

c)

.

d)

{

43.

What does the = = symbol mean in Python?

a)

Equal to or shows equality

b)

Not Equal

c)

Code that will be skipped

d)

End of clause

44.

What is the output?

a)

True

b)

False

c)

condition1

d)

condition2

45.

What is the output?

a)

250.0

b)

200.0

c)

300.0

d)

350.0

46.

What will be displayed at the end of the program?

a)

Case 1

b)

Case 2

c)

Nothing will be displayed.

d)

Case 1 and Case 2

47.

What will be displayed at the end of the program?

a)

Case 1

b)

Case 2

c)

Nothing will be displayed.

d)

Case 1 and Case 2

48.

What will display at the end of the program running?

a)

You can ride the carousel!

b)

Nothing will display

c)

You cannot ride the carousel!

d)

There will be an error.

49.

What will display at the end of the program running?

a)

You can ride the carousel!

b)

Nothing will display

c)

Sorry! Not tall enough!

d)

There will be an error.

50.

What will display at the end of the program running?

a)

You can ride the carousel!

b)

Nothing will display

c)

Sorry! Not tall enough!

d)

There will be an error.

51.

What questions do you have about If Else Statements?

4 lines
52.

What is the output?

a)

3

b)

3

7

c)

3

5

7

d)

7

53.

What is the output?

a)

True

b)

NIL

c)

True

NIL

d)

True

NIL

NIL

54.

What is the output?

a)

level 3

b)

level 3

level 1

c)

level 3

level 1

NIL

d)

level 3

level 2

level 1

NIL

55.

What part of an if statement should be indented?

a)

All of it

b)

The statements within it

c)

the first line

d)

the lines within the brackets

56.

Given the nested if-else below, what will be the value x when the code is executed successfully.

a)

0

b)

4

c)

2

d)

3

57.

Fill the blank

a)

counter=1

b)

counter<10

c)

counter<=10

d)

counter<=11

58.

What is an algorithm?

a)

A set of steps for performing a task, like a recipe.

b)

To add something to the end; for example, adding letters onto the end of a string or adding elements to the end of a list or array.

c)

A value passed to a function.

d)

A rhythm designed for people named "Al."

59.

What is an application?

a)

A computer program that does something useful (or fun!).

b)

A request to do something.

c)

A set of steps for performing a task, like a recipe.

d)

A group of programming statements.

60.

Statements or instructions written by a programmer in a language that computers can understand defines...

a)

algorithm

b)

code

c)

software

d)

range

61.

A set of instructions that is repeated until a condition is reached is

a)

a loop

b)

code

c)

a function

d)

an expression

62.

Which loop will repeat the information in the loop # times before stopping the program?

a)

Forever

b)

Repeat #

c)

Repeat until ___

63.

Which loop continues an infinite number of times unless the user stops it?

a)

Forever

b)

Repeat #

c)

Repeat until ___

64.

Which loop repeats itself until the X statement is true?

a)

Forever

b)

Repeat #

c)

Repeat until ___

65.

A ____________ is a special control block that expects a predicate (what is in the picture).

a)

Variable

b)

Predicate

c)

Conditional

d)

Reporter

66.

Which of the following could be a SPRITE? (Check as many as apply.)

a)

a tomato

b)

a sports ball

c)

a hero

d)

an animal

67.

Statements that run only under certain conditions or situations.

a)

conditionals

b)

nested loop

c)

command

d)

refactor

68.
Which block moves a sprite 10 points to the right, no matter which way it is facing?
a)
Change X by 10
b)
Change Y by 10
69.
Which of the following would be a conditional statement?
a)
When the green flag is clicked, set rotation style left-right 
b)
When right arrow is pressed move 10 steps
c)
If Lives are equal to 0 then switch backdrop
d)
When backdrop switches to Level 1, set lives to 3
70.

Select different parts of "for" looping statement-

a)

Initialization part

b)

Condition Part

c)

Update part

d)

All of these

71.

What will be the output of following code- for(int i = 1; i < 5; i++ )

{

System.out.print(i);

}

a)

13

b)

135

c)

1234

d)

12345

72.

_________ in programming come into use when we need to repeatedly execute a block of statements.

a)

nested for loop

b)

none

c)

for loop

d)

loop

73.

The __________ statement uses single expression for multiple choices

a)

loop

b)

switch

c)

multiple value

d)

if else

74.

in __________ the controlling condition appears at the start of the loop and _______ at the end of the loop

a)

While / Do while

b)

Do while/While

c)

None

75.
If there is more than one statement in the block of a for loop, which of the following must be placed at the beginning and the ending of the loop block? a.  b.  c. . d. 
a)
parentheses ( )
b)
braces { }
c)
brackets [ ]
d)
arrows < >
76.

What is an Array?

a)

A group of elements of same data type.

b)

An array contains more than one element

c)

Array elements are stored in memory in continuous or contiguous locations.

d)

All the above.

77.

In general, the index of the first element in an array is __________

a)

0

b)

-1

c)

2

d)

1

78.

What is meaning of following

declaration ?

int arr[20];

a)

Array of size 20 that can have integer address

b)

Array of Size 20

c)

Integer Array of size 20

d)

None of these

79.

Assuming int is of 2 bytes, what is the size of int arr[15];?

a)

15

b)

19

c)

11

d)

30

80.

What is the length of the following array: int data[] = { 12, 34, 9, 0, -62, 88 };

a)

1

b)

5

c)

6

d)

12

81.

If we have declared an array described below -

int arr[6];

then which of the following array element is considered as last array element ?

a)

arr[6]

b)

arr[4]

c)

arr[0]

d)

arr[5]

82.

All the arithmetic operators operate on (a)   associativity.

83.

The symbol used for conditional operator is _____

a)

?:

b)

=

c)

++

d)

>=

84.

The word algorithm is derived from the following

a)

a. AL-KHOWARIZMI

b)

b. AL-AHMED

c)

c. AL-JAFAR

d)

d. AL-MURA

85.

The special function called ____ is where program execution begins.

a)

a. Add

b)

b. Sub

c)

c. Main

d)

d. Multi

86.

Escape sequence _______ represents bell sound.

a)

a. \n

b)

b. \a 

c)

c. \t

d)

d. \b

87.

The meaning of the operator ______ is modulus in C language.

a)

a. ++

b)

b. mod

c)

c. %

d)

d. *

88.

In the following declaration,

int sum(int , int);

How many parameters are declared?

a)

a. 4

b)

b.6

c)

c. 2

d)

d. 3

89.

Function declaration or function prototype has ____ components.

a)

a. 4

b)

b. 7

c)

c. 9

d)

d. 3

90.

Use repeat block to make the code shorter.

a)

b)

c)

d)

91.

What do you think will happen when you click "Run"?

a)

BB-8 will not move.

b)

BB-8 will move only one space

c)

BB-8 will move 5 times and get all of the scrap metal

d)

BB-8 will move only 3 spaces.

92.

Use a repeat block to move tho robot and collect all scrap metals.

a)

b)

c)

d)

93.

Pick two repeat block to complete the code.

a)

b)

c)

d)

94.

Identify wrong block in this code.

a)

1

b)

2

c)

3

d)

4

95.

Use one repeat block for coding.

a)

b)

c)

d)

96.

Identify the bug (mistake) in this code?

a)

1

b)

2

c)

3

d)

4

97.

How many repetition needed to run two blocks in this code?

a)

1

b)

2

c)

3

d)

4

98.

Use one repeat block to make the code shorter.

a)

b)

c)

d)

99.

Use a repeat block to complete the code.

a)

b)

c)

d)