Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Global and local variables

Total questions: 10

Worksheet time: 7mins

Name
Class
Date
1.

A variable declared within a subroutine

a)

Global

b)

Local

2.

A variable declared in the main program

a)

Global

b)

Local

3.
The correct way to write a variable in Python?
a)
myVariable = 10
b)
my Variable = 10
c)
myVariable is 10
d)
myVariable: 10
4.

Which of the following is an advantage of using local variables?

a)

They allow the variable to be used throughout the whole program

b)

They allow variable identifiers to be reused each time

c)

They are easier to program than global variables

d)

A wider range of data types can be used

5.

What term is used to describe data passed into/out of a program?

a)

Variable

b)

Loop

c)

Constant

d)

Parameter

6.

Leo wants to create a subroutine that will roll a dice. Which syntax is correct?

a)

def dice roll ():

b)

def diceroll ()

c)

def diceroll ():

d)

def diceroll []:

7.

Which is the correct output for this program?

a)

bacon local ,spam local, bacon local, global

b)

spam local, bacon local, bacon local, global

c)

global, bacon local, spam local, bacon local,

d)

global, spam local, bacon local, bacon local

8.

What will be the output of this code?

a)

spam

b)

main program

9.

What will be the output of this code?

a)

spam

b)

bacon

c)

main program

10.

The output of the code above is

a)

40

b)

30

c)

syntax error