Quiz
CP1404
Dieses Quiz enthält Fragetypen, die sich im gewohnten Player öffnen.
Fragen in diesem Quiz (42)
1Which one of the following correctly increments by 1 the value referred to by the key ‘a’?
d = {'a': 123, 'b': 234}- Ad.values('a') += 1
- Bd.keys('a') += 1
- Cd['a'] += 1
- Dd.get('a') += 1
2What is the correct error message for the following code?
x = str(1.0)
x[-1] = '2'- AValueError: invalid literal for int() with base 10: '1.0'
- BIndexError: string index out of range
- CTypeError: 'str' object does not support item assignment
- DNameError: name 'x' is not defined
3One great tool used in IDEs like Python is the ability to rename variables/functions/classes/etc. throughout a project, which is called [blank_start]refactoring[blank_end]
- Arefactoring
4Given the code:
vehicle = Taxi('Prius')
print(vehicle.fuel)
vehicle.drive(50)
Identify the names of the parts by matching them up.
Taxi - [blank_start]class[blank_end]
vehicle - [blank_start]object[blank_end]
drive - [blank_start]method[blank_end]
fuel - [blank_start]attribute/field[blank_end]
'Prius' - [blank_start]argument[blank_end]- Aclass
- Bobject
- Cmethod
- Dattribute/field
- Eargument
5Write the function name (not including the brackets/parameters) for the function that Python calls when you print an object or convert it to a str:
[blank_start]__str__[blank_end]- A__str__
6Which method does a programmer need to define in a class in order to specify the behaviour for when the == operator is used with objects of that class?
- A__eq__
- B__cmp__
- C__equals__
- D__==__
7What is the correct error message for the following code?
x = str(int('1.0'))
x[-1] = '2'- AIndexError: string index out of range
- BValueError: invalid literal for int() with base 10: '1.0'
- CTypeError: 'str' object does not support item assignment
- DNameError: name 'x' is not defined
8def process(x, y=2, z=3):
return x + y + z
The code above demonstrates:- Akeyword arguments
- Bdefault argument values
- Cmultiple return values
- Dboth a and b
9Which one of the following is the correct class header for a Student class that extends (inherits from) the Person class?
- Aclass Student(Person):
- Bclass Student extends Person:
- Cclass (Student, Person):
- DNone of the above
10Write the function name (not including the brackets/parameters) for the standard Python class constructor.
[blank_start]__init__[blank_end]- A__init__
11What is the output of the following code?
before = [1, 4, 0, -1]
after = before.sort()
print(after[0])- A-1
- B0
- C1
- DNone of the above
12What is the output of the following code?
words = ["aye", "bee", "sea"]
print(" / ".join(words))
[blank_start]aye / bee / sea[blank_end]- Aaye / bee / sea
13Which ones (could be 0 or more) of the following are valid examples of inheritance?
- AHouse inherits from Land
- BBook inherits from Publication
- CFido inherits from Dog
- DPerson inherits from Student
- EBus inherits from Vehicle
- FCoffee inherits from Beverage
14What is the result of the following expression?
[1, 2, 3] is [1, 2, 3]
[blank_start]False[blank_end]- AFalse
15What is the output of the following code?
values = (2, 4, 6)
for x, y in enumerate(values):
print("{0}:{1:.0f}".format(x, y), end=" ")- A0:2 1:4 2:6
- B2:0 4:1 6:2
- C1:2.0 2:4.0 3:6.0
- D0:2.0 1:4.0 2:6.0
16What is the output of the following fun to read code?
print(" ".join([str(i * 2) for i in range(1, 16, 3) if i % 2 == 0]))
[blank_start]8 20[blank_end]- A8 20
17Recursive functions should always have a [blank_start]base[blank_end] case that handles when recursion should stop.
- Abase
18What is the output of the following code?
words = ["aye", "bee", "sea", "bee"]
words.remove("bee")
print(words.pop())
[blank_start]bee[blank_end]- Abee
19What is the result of the following expression?
[1, 2, 3] == (1, 2, 3)
[blank_start]False[blank_end]- AFalse
20What is the result of the following expression?
9 % 2
[blank_start]1[blank_end]- A1
21def rec_fun(n):
if n > 0:
return rec_fun(n - 1) + n * 2
return 0
print(rec_fun(4))
[blank_start]20[blank_end]- A20
22Given the line
from random import randint
“random” is a:- Aclass
- Bmodule
- Cpackage
- Dfunction
23What is the result of the following expression?
(3 >= 3) or (5 < 7) and (9 != 5)
[blank_start]True[blank_end]- ATrue
24Which one of the following data structures is the most appropriate choice for storing a collection of 2D points?
- ATwo lists
- BA dictionary
- CA class
- DA list of tuples
25What is the name for the git feature that allows you to easily create a kind of version (like a fork) starting from your current commit, which you can merge back in later?
[blank_start]branch[blank_end]- Abranch
26Which ones (could be 0 or more) of the following are mutable data types in Python?
- Alist
- Binteger (int)
- Ctuple
- Dstring (str)
- Edictionary (dict)
27Write the result of the expression:
7 % 3
[blank_start]1[blank_end]- A1
28Write the result of the expression:
5 / 2
[blank_start]2.5[blank_end]- A2.5
29Write the result of the expression (as evaluated by Python):
5 // 2
[blank_start]2[blank_end]- A2
30Write the result of the expression (as evaluated by Python):
15 / 3 + 2 * 4
[blank_start]13.0[blank_end]- A13.0
31Write the output of the following Python code:
(Note that you need to match the output exactly. Each print statement will print on the same line with values separated by spaces.)
for i in range(1, 10, 4):
print(i, i * 2, end=" ")
[blank_start]1 2 5 10 9 18[blank_end]- A1 2 5 10 9 18
32i = 0
if i > 10:
print("Control")
Which one of the following identifies all of the control structures used in the code above?- Aselection
- Bselection and sequence
- Crepetition and sequence
- Drepetition and selection and sequence
33Which one of the following is not a state that your files can be in when using Git?
- AStaging area
- BWorking directory
- CCheckout area
- DRepository
34Which one of the following is the Git command to use to create a new repository?
- Agit init
- Bgit add
- Cgit create
- Dgit new
35What is the Git operation (and command) called when you want to save a snapshot of your repository?
git [blank_start]commit[blank_end]- Acommit
36To perform interactive debugging and get the IDE to stop executing your code at a certain point, you add a [blank_start]breakpoint[blank_end]
- Abreakpoint
37Which 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():- ASomething is required between the brackets
- BThe function name is invalid
- CThis function would take no parameters and return nothing
- DNone of the above
38Given that pi is a constant stored in the math module, which one of the following will successfully import and print it?
- Aimport math
print(math.pi) - Bfrom math import pi
print(math.pi) - Cfrom math import pi
print(math.pi()) - Dimport math.pi
print(math.pi)
- Aimport math
39
What is the output of the following code?
def fn(x, y):
z = x + y
print(fn(1, 2))- A12
- BNone
- C3
- DSyntax error
40What will be the output of the following code?
x = 5
for i in range(x): x = x + i print(x, end=" ")- A5 6 7 8 9
- BNone of the above, but it will finish
- C0 1 2 3 4
- D5 6 8 11 15
41What is the type of the variable result when the following code executes?
text = "Enjoy the test" result = text.strip().split()[0]- Alist
- Bstr (string)
- Cint (integer)
- DA different type (not listed), but it will work.
- ENone of the above. This code has an error and will not work.
42What is the output of the following code?
try: x = int("zero") print(10 / x) except ZeroDivisionError: print("div") except NameError: print("name") except ValueError: print("value") except: print("other")- Avalue
- Bother
- Cdiv
- Dname
Informationen
- Beschreibung
- ICFES/Saber 11 programming Quiz am CP1404, erstellt von Alex Von Kurtz am 12/11/2016.
- Autor
- Alex Von Kurtz
- Sprache
- English
- Aufrufe
- 0
- Schlagwörter
- Bewertung
- Noch keine Bewertungen Bewerte dieses Quiz