Advanced Patterns — Series 2

Preview — 3 of 10 questions

What is the output of the following code?

javascript
x = 5
y = 3
print(x & y)
print(x | y)
print(x ^ y)
print(~x)
print(x << 2)
print(-8 >> 1)
A1, 7, 6, 6, 20, -4
B1, 7, 6, -6, 20, -4
C1, 7, 6, -6, 20, 4
D2, 7, 6, -6, 20, -4

What is the output of the following code?

javascript
def connect(host, port, timeout=30, retries=3):
    return f"{host}:{port} timeout={timeout} retries={retries}"

args = ["localhost", 8080]
kwargs = {"retries": 5}
print(connect(*args, **kwargs))
Alocalhost:8080 timeout=5 retries=3
BTypeError: connect() got multiple values for argument 'retries'
Clocalhost:8080 timeout=30 retries=3
Dlocalhost:8080 timeout=30 retries=5

What is the output of the following code?

javascript
class Animal:
    sound = "generic sound"

    @classmethod
    def make_sound(cls):
        return f"{cls.__name__} says {cls.sound}"

    @staticmethod
    def info():
        return "Animal.info called"

class Dog(Animal):
    sound = "Woof"

print(Animal.make_sound())
print(Dog.make_sound())
print(Dog.info())
AAnimal says generic sound, Dog says Woof, Animal.info called
BAnimal says generic sound, Dog says generic sound, Animal.info called
CAnimal says generic sound, Dog says Woof, Dog.info called
DDog says generic sound, Dog says Woof, Animal.info called

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.