WorksheetsPython Theory
Total questions: 17
Worksheet time: 17mins
What is a valid shebang line?
!/usr/local/env python3
#/usr/local/env python3
##/usr/local/bin/python3
#!/usr/local/bin/python3
Which line is an expression but NOT a statement?
break
x=x+1
print('hello')
True
In Python, a statement is _____.
a line of code
a function call
a combination of literals, identifiers, and operators
an operation
What will this code produce?
It will print a is 6.
It will print a is 5.
It will fail on a logical error.
It will print nothing.
What is the issue with this mock code?
The else block must come before the elif block.
An elif block cannot be followed by an else block.
The do C block may run before the do B block.
The do C block will never be executed.
Which loop type will always complete at least one iteration?
none of these answers
the until loop
the while loop
the for loop
Which statement is true regarding this function definition?
The function will not return anything.
The function will return a value of none.
The function will return the value of 5.
A syntax error will be reported.
What will this Python script print?
A
B
C
B
C
A
C
C
A
What is the purpose of Hello World?
to activate your Python account
to introduce yourself to the Python community
to validate your development environment
to communicate with other Python users
What is the equivalent f-string notation of this code?
print('x is {f(x)}')
print('x is f{x}')
print('x is {x}'.f())
print(f'x is {x}')
Why do blocks in Python need to be indented at the same level?
so they are considered grammatically correct
so they can print in readable text
so they can be edited in the same font
so they are considered part of the same block
What will the following code print?
x > y: y is 42 and X is 73
x = 42: y is 73 and x is 42
x < y: x is 42 and y is 73`
y = 73; y is 73 and x is 42
What will the following code print?
one
two
three
four
five
six
one
two
three
four
five
zero
one
two
three
four
five
`` zero one ```
What will the following code print?
0
1
error
n
In the following code, what is the object?
quack
Donald walk like a duck
Donald
walk
Will this code work? If not, how how should you fix it?
This code will work correctly, printing the height as specified.
This code will fail. To fix the code, replace format(height) in line 4 with format(self.height).
This code will fail. To fix the code, change line 2 to height=self.height.
This code will fail. To fix the code, switch the order of lines 5 and 6.
LANGUAGE OVERVIEW
What will this Python code print
A,B,C
A
B
C
A,B
C
C
A,B
