Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Programming Sandbox 3

Total questions: 100

Worksheet time: 56mins

Name
Class
Date
1.

Which two (2) lines of code will print when this function is called?

4 lines
2.

What is the name of the function?

4 lines
3.

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

a)

true

b)

false

4.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
5.

What does the following code output?

a)

11, 9

b)

16, 16

c)

None, None

d)

225, 117

6.

Consider the line of code:

Label('Go Team', 200, 100)

What is the Label?

a)

argument

b)

parameter

c)

function name

7.

Which of the following is the correct code to define a function?

a)

def area ( ):

b)

area ( )

c)

def area:

d)

def area ( )

8.
How do you correctly call this function
a)
def(1)
b)
x=square( )
c)
defSquare(4)
d)
x=square(5)
9.

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

10.

What character should be placed at the end of the function "def" line, after the parentheses?

a)

Hashtag (#)

b)

Colon(:)

c)

Exclamation (!)

d)

Dash (-)

11.

Which keyword marks a spot in a function where the program flow will go back to the calling code?

a)

break

b)

return

c)

continue

d)

jump

12.

If a function named "mystery" is defined as taking no parameters, how would you call that function from your code?

a)

#mystery

b)

mystery[]

c)

mystery()

d)

mystery

13.

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

14.

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

15.

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

16.

. Which of the following definitions for the "haunted" function will correctly set the default value for the "surprise" parameter equal to the number 1?

a)

haunted(fear, surprise) = 1

b)

def haunted(fear, surprise=1):

c)

def haunted(fear, surprise "1")

d)

def haunted[fear, surprise=1]

17.

Which of the following statements will successfully send the value "EEK" back from a function to the calling code?

a)

EEK

b)

return EEK

c)

back EEK

d)

#print(EEK)

18.

How many return statements can you place inside one function body?

a)

As many as needed; each marks a spot where program flow returns to the calling code

b)

You can have one return statement per parameter that is defined by the function "def"

c)

You are limited by the number of body statements, divided by 2

d)

Exactly one

19.

What controls a variable's scope?

a)

The location where it is first initialized within your code

b)

The comment you place to the right of the variable name

c)

The capitalization you select for the letters in your function name

d)

The length of your variable name

20.

Which of the following rules is true about locally scoped variables?

a)

Local variables can hold less data than global variables

b)

Local variables can be seen and accessed from any part of the program code

c)

Local variables will keep their same value over repeated calls to the function

d)

Local variables can only be seen and used from inside a function

21.

How would you create a program to display "Hello World!"

a)

print(Hello World!

b)

input("Hello World!")

c)

print("Hello World!")

d)

print(Hello World!)

22.

How would you create a program to display "Hello World!"

a)

print(Hello World!

b)

input("Hello World!")

c)

print("Hello World!")

d)

print(Hello World!)

23.

Which python operator means 'less than or equal to'?

a)

>=

b)

>

c)

<

d)

<=

24.
What is the word (command) used to display numbers and text on the screen?
a)
print
b)
input
c)
output
d)
command
25.
What is a variable?
a)
A box(memory location) where you store values
b)
a type of graphics
c)
Data type
d)
a type of memory
26.
What symbol is used in python to assign values to a variable?
a)
equals =
b)
plus + 
c)
forward slash /
d)
asterisk *
27.
What is the name of the programming language we are learning?
a)
Scratch
b)
Python
c)
Pie thin
d)
Scribble
28.

What will be the output?

name = "Dave"

print (name)

a)

Dave

b)

'Dave'

c)

name

d)

(name)

29.
A syntax error means your code has a 'grammar' mistake or you used symbols/operations incorrectly
a)
True
b)
False
30.
What is Python?
a)
text based programming language
b)
word processor 
c)
spreadsheet
d)
block based programming language
31.
What Python command lets the user enter an answer to a question?
a)
answer()
b)
open()
c)
print()
d)
input()
32.
Which statement correctly assigns the string "Tanner" to the variable name?
a)
name  = print( "Tanner")
b)
input("Tanner")
c)
name = "Tanner"
d)
name = input("Tanner")
33.

Which symbol means "not equal to"

a)

%

b)

==

c)

!=

d)

**

34.

What is an example of a boolean?

a)

"Hello!"

b)

56

c)

True/False

d)

46.7

35.

23 == 32

a)

True

b)

False

36.

4 == 4.0

a)

True

b)

False

c)

Error

37.

What is the purpose of a loop in programming?

a)

The purpose of a loop in programming is to repeat a block of code.

b)

The purpose of a loop in programming is to randomly select a block of code.

c)

The purpose of a loop in programming is to skip a block of code.

d)

The purpose of a loop in programming is to execute code only once.

38.

What is the output of the following code?

x = 5
y = 3
print(x + y)

a)

8

b)

2

c)

15

d)

7

39.

What will this symbol do?


\n

a)

Print

b)

Not

c)

New line

d)

Does nothing

40.

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

41.

What is a variable?

a)

a type of graphics

b)

A box(memory location) where you store values

c)

Data type

d)

a type of memory

42.

What symbol is used in python to assign values to a variable?

a)

equals =

b)

plus +

c)

minus -

d)

asterisk *

43.

What will be the output?

name = "Dave"

print (name)

a)

(name)

b)

Dave

c)

name

d)

Nothing

44.

A syntax error means your code has a 'grammar' mistake or you used symbols/operations incorrectly

a)

True

b)

False

45.

Which statement correctly assigns the string "Tanner" to the variable name?

a)

name  = print( "Tanner")

b)

input("Tanner")

c)

name= "Tanner"

d)

name = input("Tanner")

46.

What is the output from the following code?

print ("hello world")

a)

hello world

b)

print

c)

nothing

d)

"HELLO WORLD"

47.

What will be the output?

name = "Dave"

print ("name")

a)

Dave

b)

name

c)

"name"

d)

"Dave"

48.

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

a)

list

b)

for

c)

while

d)

if

49.

Loop that runs till the condition is true

a)

list

b)

while

c)

for

d)

if

50.

In Python, the two types of loops are _____ and _______

a)

while

b)

for

c)

list

d)

if

51.

Choose the correct output of the following code.

for i in range(10,15):       

print(i)

a)

10

11

12

13

14

15

b)

10

11

12

13

14

c)

11

12

13

14

15

d)

11

12

13

14

52.

What symbol do you use to make a comment in Python?

a)

+

b)

//

c)

$

d)

#

53.

What type of data is the following?: X = "195.67"

a)

Float

b)

String

c)

Boolean

d)

Integer

54.

What type of variable is the following?: Y = False

a)

Float

b)

String

c)

Integer

d)

Boolean

55.

What does the following Python program print?

X = "Hello World!"

Y = "I can code "

Z = " In Python"

print( X + Y + Z)

a)

Hello World! I can code In Python

b)

Hello World!I can code In Python

c)

Hello World! I can codeIn Python

d)

Hello World!I can code In Python

56.

Variables have three things:

a)

Numeric, string, Boolean

b)

Integer, float, string

c)

name, type, value

d)

function, value, name

57.

When you want to print something to the screen you should use

a)

The keyboard to type it

b)

The computer Display

c)

A monitor

d)

a print statement

58.

print("Python " * 3); will print out what

a)

Python 3 Python 3 Python 3

b)

Python Python Python

c)

PythonPythonPython

d)

Python*3 Python*3 Python*3

59.

Which one to the following Python programs will not run?

a)

num = 4

greeting = "Hello"

print(num + greeting)

b)

grade = 98.7

letterGrade = "A+"

print(str(grade) + letterGrade

c)

studentNum =80

print("studentNum")

d)

print("Hello World!")

60.

Which of the following is NOT a program that will produce the following output?

SeasonSeasonSeason

a)

word = "Season" * 3

print(word)

b)

word = "Season" + "Season" + "Season"

print(word)

c)

num = 3

word = "Season" * 3

print(word)

d)

word = "Season"

print(word)

print(word)

print(word)

61.

float, integer, boolean, and string are all examples of what?

a)

Variables

b)

Data Types

c)

Words

d)

Concatenation

62.

The following statement/code snippet is an example of what?

color = blue

a)

All is correct

b)

Variable/variable assignment

c)

Variable declaration

d)

Variable initialization

63.

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

a)

:

b)

;

c)

.

d)

{

64.

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

a)

conditional statements

b)

control flow statments

c)

syntax

d)

variables

65.
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:
66.
This operator means that one value is the same as the other value
a)
==
b)
!=
c)
>
d)
<
67.

What is the output?

a)

more than 7

b)

more than 23

c)

spam

d)

7

68.

In what situation it will display the butterfly image?

a)

When i is less than 5

b)

When i is greater than 5

c)

When i is greater and equal to 5

d)

Any situation

69.

Else if (elif) is used in which situation?

a)

If the previous conditions were not true

b)

You can use if statement to replace elif

c)

else is enough for now

d)

Any situation

70.

What is elif in Python?

a)

eliminate if

b)

else if

c)

A person's name

d)

False

71.

What will this output?

a)

Mine is too!

b)

An error

c)

MINE IS TOO!

d)

Nothing

72.

What would be outputted here?

a)

it divides by 7!

b)

it divides by 3.

c)

It divides by 7!

d)

It divides by 3.

73.

What will this program output?

a)

:(

b)

":("

c)

Error

d)

nothing

74.

What will be the output of this code?
x = 14

y = 13

y = x + 3

if x<=y:

print("Hurray")

else:

print("Yay")

a)

Hurray

b)

Yay

c)

14

d)

13

75.

What will be the output of this code?
x = 13

y = 14

if x!=y:

print("Hello")

else:

print("Hi")

a)

Hello

b)

Hi

c)

14

d)

13

76.

What will be the output of this code?
x = 13

y = 14

if x==y:

print("Hello")

else:

print("Hi")

a)

Hello

b)

Hi

c)

13

d)

14

77.

In Python, what are if-statements used for?

a)

Looping

b)

Indexing

c)

Decision Making

d)

Testing

78.

Look at the following code:

name = "John"

age = 23

What type of data is stored in the variable name?

a)

str

b)

int

c)

float

d)

nothing

79.

Look at the following code:

name = "John"

age = 23

What type of data is stored in the variable age?

a)

str

b)

int

c)

float

d)

nothing

80.

Look at the following code:

name = "John"

age = "23"

What type of data is stored in the variable age?

a)

str

b)

int

c)

float

d)

nothing

81.

If I want to store my height in a variable, which of the following would be a good variable name in best practice?

a)

abcdefg

b)

inches

c)

number

d)

height

82.

If I want to store my name in a variable, which of the following would be a good variable name in best practice?

a)

name

b)

teacher

c)

mister

d)

abcdef

83.

If I want to store multiple names in variables, which of the following would be good variable names in best practice?

a)

a

b

c

b)

name1

name2

name3

c)

Audrey

Ben

John

d)

blah1

blah2

blah3

84.

Look at the following code:

age = "23"

age = int(age)


What does the int() function do to the data in my variable?

a)

does nothing

b)

changes the string to a float

c)

changes the number to a string

d)

changes the string to an integer

85.

Look at the following code:

age = 23

age = float(age)


What does the float() function do to the data inside age?

a)

changes the string to an int

b)

changes the int to a string

c)

adds a decimal point (23.0)

d)

does nothing

86.

What is the output?

a)

more than 7

b)

more than 23

c)

spam

d)

7

87.

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

88.
An if statement must evaluate to:
a)

Right or Wrong

b)

True or False

89.
This operator means that one value is the same as the other value
a)

==

b)

!=

c)

>

d)

<

90.

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

91.
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.
92.

What will happen when this program is run?

a)

Syntax error

b)

One will be displayed

c)

Zero will be displayed

d)

One then Zero will be displayed

93.

What will happen when this program is run?

a)

Syntax error

b)

Big will be displayed

c)

Small will be displayed

d)

300 will be displayed

94.
What does “==” represent in Python programming?
a)
less than
b)
equal to
c)
greater than
d)
not equal to
95.
Choose the correct Python code.
if age is less than 20 then
a)
if age > 20:
b)
if age < 20:
96.

What is the name of the variable in this program?

a)

print

b)

colour

c)

input

d)

" "

97.

What symbol must you place at the end of an if statement?

a)

)

b)

:

c)

;

d)

}

98.

1==0

a)

True

b)

False

99.
A line of text that Python won't try to run as code
a)
comment
b)
modulus
c)
variable
d)
boolean
100.
What symbol is used in python to assign values to a variable?
a)

=

b)

; 

c)

:

d)

==

Similar Resources on Wayground