Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

CP 1 Review 2023

Total questions: 37

Worksheet time: 19mins

Name
Class
Date
1.

Which version of Python are you learning in this course?

a)

3

b)

2

c)

1

d)

Any version will work equally well

2.

Which of the following best describes an Integrated Development Environment (IDE)? 

a)

Software that helps you create and run code 

b)

Software that helps you design programs before you start coding 

c)

Software that helps you create audio, video, and images for your program

d)

Software that helps you track your program sales

3.

 What character do you place at the end of a line to break a long statement across multiple lines? 

a)

A backslash (\) 

b)

A hash-tag (#) 

c)

A colon (:) 

d)

An extra space

4.

Which of the following variable names are valid in Python?

a)

All of these are valid

b)

Testing123

c)

 testing_123 

d)

TESTING

5.

Which of the following statements will add 10 to the value in the "mystery" variable and store the answer in the "result" variable?

a)

result = 10 + mystery

b)

 mystery = result - 10

c)

 result = mystery(10)

d)

mystery + 10 = result

6.

Given a variable named "mystery", which of the following statements will display the data type of that variable?

a)

print(type(mystery))

b)

 print(mystery

c)

) mystery.type() 

d)

No such statement exists

7.

What is the printed output from the following statement? print("Testing" + "Testing") 

a)

TestingTesting

b)

Testing Testing 

c)

class 'str' 

d)

An error message 

8.

What is the displayed output when the following statement is run? print("phone","number",sep="#") 

a)

phone#number

b)

phone number

c)

phonenumber

d)

 "phone" on one line and "number" on the next

9.

What is wrong with the following code? 

ageInYears = input("How old are you? ") ageInDays = ageInYears * 365

a)

ageInYears is a string and can't be used in a mathematical expression

b)

* is not the correct symbol for multiplication 

c)

The question inside the input() parentheses should not be surrounded by double quotes

d)

input() is missing a required timeout parameter

10.

What text is displayed on output by the following statement? print(str.format("#{0:4}#", "dog") ) #dog # #dog# dog

a)

#dog # 

b)

#dog#

c)

Dog

d)

 ## 

11.

Which of the following comparison operators means "not equal to"? 

a)

!=

b)

 <

c)

 >=

d)

 !<>

12.

What will be output to the screen when the following code is run?

 secret = 50

 if (secret == 100): 

print("Excellent")

elif (secret < 75): 

print("Awesome")

else: 

print("Super")

a)

Awesome

b)

 Excellent

c)

 Super

d)

 None of these is true

13.

 Which of the following operators will produce a True result only if both joined expressions are True?

a)

 and

b)

or

c)

not

d)

!=

14.

What type of value is held in the "answer" variable after the following code runs? answer = (1 + 5) >= (6 - 1)

a)

 Boolean 

b)

Integer

c)

 Floating point

d)

String

15.

Which of the following is the best example of a runtime error?

a)

An incorrectly written mathematical expression provides the wrong result 

b)

A missing parentheses in the source code

c)

A missing double-quote around a string value 

d)

A comment is not started with the hashtag (#) symbol

16.

Which of the following best describes a program trace? 

a)

A temporary print() statement that gives you clues as to how the program is running

b)

 An input() statement that lets the user enter debugging information 

c)

The leftover data stored in memory after the program finishes running

d)

The process you go through to find a program that meets your needs

17.

Which of the following is NOT a common Python debugger command?

a)

 fix (f)

b)

 step (s) 

c)

continue (c) 

d)

All of these are common debugger commands 

18.

Which of the following best describes the difference between a list and a tuple? 

a)

List contents can be changed, while tuple contents cannot be changed after the tuple is initialized

b)

 Lists can store any data type, while tuples are restricted to a single data type

c)

Lists can store small numbers of elements, while tuples are better at storing larger data sets

d)

 Nothing is different; lists and tuples are just two names for the same thing in Python

19.

Which of the following list functions will NOT work on a tuple? 

a)

pop() 

b)

index() 

c)

count()

d)

These will all work on a tuple

20.

What is the output of the following code?

 hobby = "marbles"

for letter in hobby: 

print("#" + letter,end="") 

a)

#m#a#r#b#l#e#s 

b)

Marbles

c)

 ####### 

d)

Syntax error; you cannot iterate over the letters in a string using a "for" loop

21.

Which keyword would you use to halt the current loop iteration and immediately continue at the top of the loop again?

a)

continue

b)

break

c)

return

d)

Jump

22.

How would you display the value of a variable holding a date, time or datetime object in a simple, default format?

a)

 Pass the variable name into the print() function as a typical parameter 

b)

Write the variable name, then a dot and then the print() function

c)

Write the variable name, then a dot and then the toString() function

d)

Call the timeString() function and pass in the variable name

23.

Which of the following statements will successfully build a date object that holds the current date? 

a)

rightNow = datetime.date.today()

b)

rightNow = datetime.datetime.current()

c)

 rightNow = today(date) 

d)

rightNow = datetime.current(date)

24.

What is the effect of calling random.shuffle() on a list? 

a)

The items in the list are re-ordered randomly

b)

Each item in the list gets a new random value

c)

 The items in the list are sorted from smallest to largest

d)

 A random number of items in the list are removed completely

25.

Which of the following is a constant value defined by the Python math library?

a)

 Both of these are true

b)

 Math.pi

c)

 math.e

d)

Neither of these is true 

26.

What is the output when the following code runs? 

food = "PIZZA" 

print( len(food) )

a)

5

b)

4

c)

6

d)

Runtime exception - the len() function does not work on strings 

27.

Which of the following best describes the str.split() function?

a)

It returns a list of individual words within a string, using white space as a default separator

b)

It breaks a string in half and returns the first part 

c)

t copies an original string value into a new variable

d)

 It builds one new string from all of the even-numbered characters and a second string from the oddnumbered characters 

28.

If you want to ensure user input is both numeric and within a specific range, which of the following types of code should be used in the validation? 

a)

Both conditional logic and try / except protection 

b)

Conditional logic only

c)

 try / except protection only

d)

It's not possible to restrict numeric input to a range

29.

Given the following function definition:

def sound_horn(): 

print("Beep, Beep!") 

How would you call this function in your code?

a)

 sound_horn()

b)

 call horn 

c)

def sound_horn() 

d)

call sound_horn()

30.

Which of the following is true about data returned from a function?

a)

All of these are true

b)

 You can ignore it 

c)

You can store it in a variable for later use 

d)

You can use it immediately in some other expression or statement 

31.

A function's input parameters are treated as __________ scope variables.

local

a)

local

b)

global

c)

international

d)

general

32.

When a function is defined within a class, it is also called a ___________. 

a)

method

b)

variable

c)

value

d)

Object

33.

Given the following code, how and where would you define a method belonging to this object?

 class Clock:

 hour = 10

 minute = 35

a)

With a "def" statement, indented to the right underneath the "class" statement and class variable initializations 

b)

With a "function" statement located above the "class" statement 

c)

With a "def" statement below the "class" statement, aligned on the left with no indentation

d)

With a "method" statement located above the "class" statement and indented to the right

34.

Our online Python engine will display multiple source files in different tabs. Which tab is always used as the main program code that will run first? 

a)

The left-most tab 

b)

The right-most tab 

c)

The tab with the asterisk (*) next to it

d)

The tab that you double-click on to start the program

35.

Given the code below, which of the following answers will create an instance variable named "treat" on the object held in the "myDog" variable? 

class Dog: 

def speak():

print("WOOF") 

myDog = Dog()

a)

 myDog.treat = "Bone"

b)

Dog.treat = "Bone" 

c)

treat = Dog("Bone")

d)

Dog[treat] = "Bone"

36.

Consider the class definition below. What is the purpose of the init() method? 

class Dog:

def init(self, aName): 

self.name = aName 

a)

To ensure an instance variable called "name" is always initialized when an object instance is created 

b)

To ensure that no code outside of the "Dog" class can access the "name" variable 

c)

To let the main program code change the Dog's name after the object is created

d)

To create a new variable called "self" and set it equal to "name"

37.

Which Python keyword can you assign to a variable to completely remove any object or value from that variable? 

a)

None

b)

Clear

c)

Delete

d)

Void