Font size
WorksheetsCodeHS Python Cert Rev 1
Total questions: 65
Worksheet time: 2hrs 31mins
Please answer the question in the image:
A
B
C
D
Please answer the question in the image:
A
B
C
D
Please answer the question in the image:
A
B
C
D
Please answer the question in the image:
A
B
C
D
Please answer the question in the image:
A
B
C
D
Please answer the question in the image:
A
B
C
D
Please answer the question in the image:
A
B
C
D
Please answer the question in the image:
A
B
C
D
Please answer the question in the image:
A
B
C
D
In python, what is output?
Built-in tools, such as print
Text in parentheses
The name of a variable
The result of the code, what is seen when it runs
In python, what is a function?
Built-in tools, such as print
Text in parentheses
The name of a variable
The result of the code, what is seen when it runs
In python, what is a parameter value?
Built-in tools, such as print
Text in parentheses
The name of a variable
The result of the code, what is seen when it runs
Which of these is NOT a type of data that can be a variable?
Comments
Integers
Strings
Boolean values
Info a program receives from a user is:
Input
Output
String
Comment
Error
A line of code ignored by the computer is:
Input
Output
String
Comment
Error
A series of letters, numbers, or symbols in quotation marks is:
Input
Output
String
Comment
Error
What is it called when you join two strings together with the + symbol?
Assignment
Concatenation
Value
Float
Integer
What is a number that has a decimal point?
Assignment
Concatenation
Value
Float
Integer
What is a whole number?
Assignment
Concatenation
Value
Float
Integer
What is the process for storing a variable? (x = y, for example?)
Assignment
Concatenation
Value
Float
Integer
What symbol is used at the beginning of an in-line comment?
"
!
#
/
Which of the statement are NOT true about comments:
Written for humans to read and understand
Helps other programmers understand your code
Helps keep the programmer organized
Only needed when a program is over 50 lines
What punctuation is needed to begin a multi-line comment?
$
"""
*
/
What syntax would you use to create a name variable?
name=input()
input=name
name=input{}
name=INPUT
Which operator checks if a value is equal to another value?
+
=
==
!=
How many times will the following loop run?
3 times
4 times
5 times
The loop will run indefinitely
Which of the following is true about the following code?
The code contains a syntax error
The code contains two comments
The code will print the comments to the console
The code will not run because of the comment on line 2
What is the result of executing the following list operation?
[1, 6, 7, 5]
[1, 2, 3, 6, 7]
[6, 7, 5]
[1, 6, 7, 7, 5]
What is the purpose of the continue statement in loops? Select ALL that are TRUE! (multiple correct answers)
It passes control to the next iteration of the loop, or ends the loop if there is no next iteration.
It exits the loop immediately
It restarts the loop from the beginning
It skips the rest of the code inside the loop for the current iteration
What will be the output of the following code?
['data']
['data', 'data']
[]
An error occurs
What is the output of the following code snippet? guess = '65.83' print(float(guess) + 1)
66.83
66
65.84
66.8
Which operator should be used in place of "?" to make the following expression evaluate to True? (5 ? 3) and (2 < 4)
>
<=
!=
==
What is the result of the following? print(17 % 3)
5
4
3
2
In a number guessing game, which conditional statement would check if `guess` is equal to `15`?
if guess = 15:
if guess == 15:
if guess: 15
if guess is 15:
What will the following loop print for a number guessing game where `number` is `10`? for i in range(3): if i == number: print("Correct!") break print("Incorrect!")
Correct!
Incorrect!
Correct! Incorrect! Incorrect!
Incorrect! Incorrect! Incorrect!
In which case will the loop continue indefinitely? while guess != number: guess = int(input("Enter your guess: "))
`guess` is initialized as a string
`number` changes within the loop
`guess` is initialized with the same value as `number`
`input` function is not used
In Python, what symbol is used to begin a comment?
//
/*
#
In Python, which of the following is an error?
Starting a line with a space
Having extra spaces at the end of a line
Not indenting under a function definition
Using tabs for indentation
How can you define a function `is_correct_guess` to accept two parameters, `guess` and `number`?
def is_correct_guess[guess, number]:
def is_correct_guess{guess, number}:
def is_correct_guess(guess number):
def is_correct_guess(guess, number):
In the context of a number guessing game, which error will be raised if an input is not an integer?
TypeError
ValueError
IndexError
KeyError
Given the list `numbers = [1, 2, 3, 4]`, how would you add the number `5` to the end of the list?
numbers.append(5)
numbers.add(5)
numbers += 5
numbers.insert(5)
For `matrix = [[1, 2], [3, 4]]`, how do you access the element `3`?
matrix[1][0]
matrix[1][1]
matrix[2][1]
matrix[0][1]
In the string `'Guess: 15'`, how can you extract only the number as an integer?
int('Guess: 15'[6:])
int('Guess: 15'.split()[1])
'Guess: 15'[7:].to_int()
'Guess: 15'.split(':')[1].int()
Which string method would you use to check if a string `s` starts with "Guess"?
s.startswith("Guess")
s.begin("Guess")
s.starts("Guess")
s.begin_with("Guess")
If `guess = " 15 "`, which of the following would remove the leading and trailing spaces?
guess.strip()
guess.remove_spaces()
guess.no_spaces()
guess.trim()
What is the benefit of using the break command as in the program below?
The user can enter as many answers as they want
The program will break out of the loop as soon as the user enters the magic_number
The loop will prompt the user to enter a number no matter what input they give
The loop will give the magic_number after a certain number of tries
What will be printed to the screen when this program is run?
100 0 -75 -125 -150
-150
-175
175
What does this program print?
It’s still a nice day
It’s still a nice day
It’s still a nice day
It’s still a nice day
It’s still a nice day
It’s still a nice day
It’s still a nice day
It’s still a nice day
It’s still a nice day
It’s still a nice day
It’s still a nice day
It’s still a nice day
It’s still a nice day
It’s still a nice day
What is the value of sum when this loop completes?
8
9
20
0
Which of the following while loops would continue to loop as long as num has values between the range of 3-12, exclusive?
while num > 12 and num < 3:
# do something with num
while num < 12 or num < 3:
# do something with num
while num <= 12 and num >= 3:
# do something with num
while num < 12 and num > 3:
# do something with num
If the user enters ‘4’, I want the loop to exit. Where should the break command be placed in order to end the loop when the user enters this value?
Line 3
Line 5
Line 7
Line 9
Which of the following for loops would print the following numbers?
3 5 7 9
for i in range(3, 10, 2):
print(i)
for i in range(3, 9, 2):
print(i)
for i in range(9):
print(i)
for i in range(3,9):
print(i)
What does this program print?
0 1 2
0 1 2 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9
0 1 2 3
When would a while loop be a better control structure to use than a for loop?
When you need to repeat multiple commands
When you need to repeat something 5 times
When you don’t know how many times something will need to repeat
When the user is inputting how many times to repeat something
What is the value of num when this loop completes?
2
8
12
20
Three of the for loops below will provide identical values for i. Which for loop will provide values that do not match the others?
for i in range(0, 5):
for i in range(5):
for i in range(0, 5, 1):
for i in range(5, 0, 1):
Which of the following for loops would print the following numbers?
0 1 2 3 4 5
for i in range(5):
print(i)
for i in range(1, 5, 1):
print(i)
for i in range(6):
print(i)
for i in range(0, 5, 1):
print(i)
Which of the following while loops will cause an infinite loop?
What will be printed to the screen when this program is run?
0 1 0 1
0 2
0 1 0 1 0 1
1 2 1 2 1 2
Which of the following for loops will give the same values for i as the loop below?
for i in range(10):
for i in range(11, 0):
for i in range(10, 0, -1):
for i in range(0, 10):
for i in range(0, 11, 1):
