qšwefwsedhndrtjk
dsagsadfga
5 // 2
2
a = open(b, c)
d = a.read()
answers:
a.close()
close(b)
b.close()
None of the above
a.close()
def fn(x, y):
z = x + y
print(fn(1, 2))
What will this result in?
Syntax error
12
None
3
None
What is the Git operation (and command) called when you want to save a snapshot of your repository?
Commit
What kind of loop should a programmer usually choose when the number of iterations is known in advance (e.g. do something 10 times)?
for loop
Every if statement must have a corresponding else statement.
False
text = "Enjoy the test"
result = text.strip().split()[0]
What will this result in?
list
str (string)
int (integer)
A different type (not listed), but it will work.
None of the above. This code has an error and will not work.
str (string)
Which one of the following is the Git command to use to create a new repository?
Answers:
git new
git create
git init
git add
git init
def process(x, y=2, z=3):
return x + y + z
Answers:
keyword arguments
default argument values
multiple return values
both a and b
default argument values
x = 10
while x > 4:
print(x, end=" ")
x = x - 2
Outputs of x, in order:
10 8 6
nums1 = [1, -5, 2, 0, 4, 2, -3]
nums2 = [1, -5, 2, 4, 4, 2, 7]
result = 0
j = 0
while j < len(nums1):
if nums1[j] != nums2[j]:
result = result + 1
j = j + 1
output of j:
2
x = str(1.0)
x[-1] = '2'
Answers:
NameError: name 'x' is not defined
ValueError: invalid literal for int() with base 10: '1.0'
TypeError: 'str' object does not support item assignment
IndexError: string index out of range
TypeError: 'str' object does not support item assignment
Which one of the following is not a state that your files can be in when using Git?
Answers:
Working directory
Checkout area
Staging area
Repository
Checkout area
before = [1, 4, 0, -1]
after = before.sort()
print(after[0])
Answers:
-1
0
1
None of the above
None of the above
result = 0
for j in range(0, len(numbers)):
if numbers[j] < 0:
result = result + 1
whats the purpose of this?
to add 1 to each of the negative numbers in the list
to sum the negative numbers in the list
to count the negative numbers in the list
to find the index of the first negative number in the list
to find the smallest number in the list
To count the negative numbers in the list
x = 5
y = 10
if x < 10:
if y > 10 and x > 5:
print("A")
else:
print("B")
Answers:
The condition "y > 10 and x > 5" is invalid.
There is no else statement for the second if statement.
The indenting is incorrect.
None of the above. There is nothing wrong with this code.
None of the above. There is nothing wrong with this code.
for i in range(1, 10, 4):
print(i, i * 2, end=" ")
What is output?
5, 10
One great tool used in IDEs like Python is the ability to rename variables/functions/classes/etc. throughout a project, which is called ...
Refactor
words = ["aye", "bee", "sea", "bee"]
words.remove("bee")
print(words.pop())
output:
bee
x = 5
for i in range(x):
x = x + i
print(x, end=" ")
print all x outputs in order!:
5 6 8 11 15
try:
x = int("zero")
print(10 / x)
except ZeroDivisionError:
print("div")
except NameError:
print("name")
except ValueError:
print("value")
except:
print("other")
what will it print?
value
Which of the following is true about the following function header?
(Note that this is intentionally just one line of code; it is missing the body of the function.)
def func_2():
Answers:
Something is required between the brackets
The function name is invalid
This function would take no parameters and return nothing
None of the above
None of the above
To perform interactive debugging and get the IDE to stop executing your code at a certain point, you add a ______.
Breakpoint
values = [1, 2, 3, 2]
values.remove(2)
print(values)
Answers:
[1, 2, 2]
[1, 3]
[1, 3, 2]
None of the above
[1, 3, 2]