Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

3rd SW - ZLGA - Fund. of CS

Total questions: 45

Worksheet time: 27mins

Name
Class
Date
1.

A while loop can be used in which of the following situations?

a)

Repeat a set of statements till a condition remains True.

b)

Repeat a set of statements a finite or an infinite number of times.

c)

Iterate through a string, list, and tuple.

d)

All of the above

2.

Kind of loop used when you know the number of times you want it to repeat

a)

list

b)

for

c)

while

d)

if

3.

Which variable correctly stores a string value?

a)

greeting = hello

b)

greeting = 81

c)

greeting = "hello"

d)

greeting = 45.8

4.

__________ are used to make logical associations between boolean values.

a)

Operands

b)

Operators

c)

logical operators

d)

mathematical operators

5.

Loop that runs till the condition is true

a)

list

b)

while

c)

for

d)

if

6.

Kind of loop used when you know the number of times you want it to repeat

a)

list

b)

for

c)

while

d)

if

7.

What is an iteration?

a)

A single loop

b)

Repeated execution of a list of statements.

c)

Repeated execution of loops

d)

Repeated execution of variables

8.

Terminates the loop statement and transfers execution to the statement immediately following the loop

a)

pass statement

b)

continue statement

c)

break statement

9.

Causes loop to skip the remainder of its body and immediately retest its condition to reiterating

a)

continue statement

b)

break statement

c)

pass statement

10.

break will break out of an iteration

a)

true

b)

false

11.

continue will move to the next iteration

a)

true

b)

false

12.

A range will go to the last number listed but not include it

a)

true

b)

false

13.

If there is a circumstance where you do not want to break out of a loop, but just skip a certain value, you would use

a)

skip

b)

break

c)

continue

14.

Which kind of loop would be used?


I need a guessing game program that will let me keep guessing until I get the right answer.

a)

FOR Loop

b)

WHILE Loop

15.

Which kind of loop would be used?


I need a revision program that will run through revision questions 4 times.

a)

FOR Loop

b)

WHILE Loop

16.

You can use one or more loop inside any another while, for or do..while loop.

a)

while loop

b)

for loop

c)

nested loop

d)

infinite loop

17.

This loop condition never becomes FALSE.

a)

while loop

b)

for loop

c)

nested loop

d)

infinite loop

18.

Which one of the statements below will cause an error?

a)

ans = “hi” * 8

b)

ans = “hi” + 9

c)

ans = “hi” + “hi” + “hi”

d)

ans = (“a” * 4) + “b”

19.

Which of the following statements is true about print statements?

I. In order to print a string literal, the string must be enclosed in quotes.

II. Each print statement will be printed on its own line.

III. Print statements will not let you print string and number characters in the same statement.

IV. Print statements are how you display text on the screen.

a)

I, IV

b)

II, III

c)

I, II, IV

d)

I, III, IV

20.

Suppose you have a variable defined a = "4". What is the variable type of a?

a)

str

b)

int

c)

float

d)

number

21.

Which of the following choices is NOT a Python variable type?

a)

int

b)

str

c)

float

d)

number

22.

In what order should these statements be executed in order to get input from the user and print out the result?

A) response = input("Do you like cheese? ")

B) print("You have chosen " + confirm)

C) print("You responded " + response)

D) confirm = input("Are you sure? ")

a)

A, B, C, D

b)

B, C, A, D

c)

A, C, D, B

d)

C, B, A, D

23.
The second part of if, that is executed when the condition is false
a)
if
b)
else
c)
for
d)
input
24.
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:
25.

What is the output?

a)

more than 7

b)

more than 23

c)

spam

d)

7

26.

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

a)

conditional statements

b)

control flow statments

c)

syntax

d)

variables

27.

Which symbol means "not equal to"?

a)

==

b)

<=

c)

>=

d)

!=

28.

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

a)

:

b)

;

c)

.

d)

{

29.

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

30.

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

31.

Which of the following for loops would print the following numbers?

3

5

7

9

a)

for i in range(3, 10, 2):

print i

b)

for i in range(3, 9, 2):

print i

c)

for i in range(9):

print i

d)

for i in range(3,9):

print i

32.

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

33.

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

34.

What is the output?

a)

next

stop

b)

next

c)

stop

d)

syntax error - program doesn't work

35.

True/False: The body of an "if" statement will only be executed if the condition is true.

a)

True

b)

False

36.

How many "if" statements can a single program have?

a)

<10

b)

<20

c)

<30

d)

As many as is needed

37.

What is a flowchart used for in programming? click all of the correct answers

a)

planning

b)

building

c)

testing

d)

debugging

38.

Flowcharts can be used for which of the following:

a)

programming

b)

accounting

c)

science

d)

architecture

e)

all of the above

39.

What is the name of the function?

4 lines
40.

When defining a function, the definition must occur before it is called.

a)

true

b)

false

41.

How do you identify the statements that belong to the body of a function?

a)

Indent those statement the same amount underneath the function "def" statement

b)

Add opening and closing curly braces { and } to mark the start and stop of the function body

c)

Add the "def" keyword to the beginning of each statement

d)

Add the same comment (#) to the right of each statement within the body

42.

Which of the following best describes where you should define your function in your code?

a)

Near the bottom of the source file, after that function is called by any main program code

b)

Always place functions in a separate source file

c)

Near the top of the source file, before that function is called by any main program code

d)

The location is not important, so place the function wherever you like

43.

Which of the following is NOT a Python rule for naming functions?

a)

Functions names can contain letters, numbers and underscores

b)

Function names must be less than 32 characters

c)

The first character in a function name cannot be a number

d)

Function names are case-sensitive

44.

Which of the following statements correctly defines a function named "haunted" that takes a parameter named "apple"?

a)

haunted(apple)

b)

haunted

c)

def haunted(apple):

d)

apple

45.

What will be the output of the following program?

a)

Tracy

b)

hello Turtle

c)

Turtle

d)

hello Tracy