What is the output of this code?
def numplustwo(x):
x += 2
y = 2
numplustwo(y)
print(y)
Options
2
None
4
Error
2
davidmacago posted 2 years ago
What is the output of this code?
def numplustwo(x):
x += 2
y = 2
numplustwo(y)
print(y)
Options
2
None
4
Error
2
Why are functions with well-defined responsibilities preferable in programming?
They make the code slower but more organized.
They require less documentation
They make debugging more challenging.
They allow for easier modification and updating of specific parts of the code.
They allow for easier modification and updating of specific parts of the code.
fruits = {'apple': 1, 'banana': 2, 'cherry': 3}
print('grape' in fruits)
Error
None
False
True
False
What is the output of this cote?
set_a = {1, 2, 3, 4, 5}
set_b = {3, 4, 5, 6, 7}
print(set_a | set_b)
print(set_a & set_b)
print(set_a - set_b)
{1,2,3,4,5,6,7}
{3,4,5}
{1,2}
{1,2,3,4,5,6,7}
{3,4,5,6,7}
{1,2,3,4,5,6,7}
{1,2,6,7}
{3,4,5}
{1,2,6,7}
{1,2,3,4,5}
{3,4,5}
{1,2}
{1,2,3,4,5,6,7}
{3,4,5}
{1,2}
What is the output of this code?
data = {'x': {'y': 10, 'z': 20}, 'w': 30}
print(data['x']['z'])
Options
None
20
30
10
20
What is the output of this code?
b = 10
def modify_b():
global b
b = 5
return b
b = modify_b() + 3
print(b)
5
3
10
8
8
What is the output of this code?
def add(x, y):
return x + y
total = add(10, 20)
total = add(total, 5)
30
35
15
25
35
Which call will correctly find the maximum value in the list
nums = [5, 10, 15, 20, 25]
using the following function?
def max_value(*args):
return max(args)
max_value(nums[0])
max_value(nums)
max_value([*nums])
max_value(*nums)
max_value(*nums)
What is the output of this code?
x = [1, 2, 3]
y = [1, 2, 3]
print(x == y, x is y)
False, False
True, True
True, False
False, True
True, False
What is the output of this code?
data = {'x': {'y': 10, 'z': 20}, 'w': 30}
print(data['x']['z'])
20
30
10
{'y': 10, 'z': 20}
20
What is the output of this code?
def subtract(a, b):
return a - b
print(subtract(b=5, a=10))
10
-5
15
5
5
What is the output of this code?
for i in range(1, 6):
if i == 3:
break
print(i)
1,2
1,2,3,4,5
1,2,3
1,2,4,5
1,2
What is the output of this code?
for i in range(2, 9, 3):
print(i)
2, 4, 6, 8
2, 5, 7
2, 5, 8
2, 5
2, 5, 8
What will be printed from this code?
for number in range(10):
if number % 2 == 0:
continue
print(number)
All even numbers from 0 to 9
All odd numbers from 0 to 9
All numbers from 0 to 9
No numbers
All odd numbers from 0 to 9
Which of the following correctly defines a class in Python?
new MyClass():
pass
def MyClass:
pass
class MyClass:
pass
MyClass = class():
pass
class MyClass:
pass
What is the name of the method used to initialize a new object (constructor) in Python?
__str__()
__init__()
__main__()
__new__()
__init__()
How do you define a class B that inherits from another class A in Python?
class A(B):
pass
class B(A):
pass
class B:
inherit A
B: class(A):
pass
class B(A):
pass
What is the difference between a class variable and an instance variable in Python?
There is no difference in Python; they are treated the same way.
Class variables can only be integers, while instance variables can be any type.
Instance variables are declared outside any method, while class variables are declared within methods.
Class variables are shared across all instances of a class, while instance variables are specific to each object.
Class variables are shared across all instances of a class, while instance variables are specific to each object.
How do you correctly access an instance variable name within a method of the same class in Python?
def method_name(self):
return self.name
def method_name(name):
return name
def method_name():
return name
def method_name(self):
return name.self
def method_name(self):
return self.name



