Python 3エンジニア認定基礎試験~模擬試験④~

1. 
リストvalues = [5, 3, 8, 1, 9]を昇順にソートするにはどうすればよいでしょうか?

2. 
次のコードの出力結果は何ですか?

a = 20
b = 4
result = a // b + a % (b + 1) * a / b
print(result)

3. 
次のコードについて、インスタンスの正しい説明を選んでください。

class MyClass:
pass

obj = MyClass()

4. 
次のコードの実行結果を選んでください。

class MyClass:
def __init__(self, name):
self.name = name

obj = MyClass("Bob")
del obj.name
print(obj.name)

5. 
次のコードの実行結果を選んでください。

class MyClass:
def __init__(self, items):
self.items = items

obj = MyClass([1, 2, 3])
obj.items.append(4)
print(obj.items)

6. 
次のコードについて、インスタンス変数の変更方法として正しいものを選んでください。

class MyClass:
def __init__(self, value):
self.value = value

7. 
次のコードの出力は何でしょうか?

numbers = [1, 2, 3, 4, 5]
print(numbers[::-1])

8. 
次のコードについて、正しい出力を選んでください。

class MyClass:
pass

obj = MyClass()
print(isinstance(obj, MyClass))

9. 
次のコードの出力は何でしょうか?

fruits = ['apple', 'banana', 'cherry']
print(fruits[-2])

10. 
次のコードを実行した場合の出力は何ですか?

multiply = lambda x, y: x * y
print(multiply(3, 4))

11. 
次のコードで、変数x = 10を埋め込んで「Value: 10」と出力するための正しい記述はどれですか?

12. 
次のコードの実行結果を選んでください。

class MyClass:
def __init__(self, name):
self.name = name

def greet(self):
return f"Hello, {self.name}!"

obj = MyClass("Alice")
print(obj.greet())

13. 
次のコードを実行した場合、出力は何ですか?

from collections import deque
dq = deque([1, 2, 3, 4], maxlen=4)
dq.append(5)
print(dq)

14. 
次のコードを実行した場合の出力は何ですか?

subtract = lambda x, y=5: x - y
print(subtract(10))

15. 
次のコードを実行したときの出力結果は何でしょうか?

square_diff = lambda x, y: (x - y) ** 2
print(square_diff(7, 5))

16. 
次のコードの実行結果を選んでください。

class MyClass:
def __init__(self, value):
self.value = value

def reset(self):
self.value = 0

obj = MyClass(10)
obj.reset()
print(obj.value)

17. 
次のコードの出力結果は何ですか?

a = 15
b = 4
print(a - b)

18. 
次のコードを実行した場合の出力は何ですか?

a = 10
b = 3
result = a ** b % (a - b)
print(result)

19. 
次の出力を得るためには、どのようなコードを入力すべきですか?

Binary: 1101

20. 
次のコードの出力は何でしょうか?

numbers = [2, 4, 6, 8]
result = [x ** 2 for x in numbers if x % 4 == 0]
print(result)

21. 
次のコードを実行した場合、出力は何ですか?

from collections import deque
dq = deque(["a", "b", "c"])
dq.appendleft("z")
print(dq)

22. 
次のコードの出力として正しいものはどれですか?

double = lambda x: x * 2
print(double(double(2)))

23. 
次のコードの出力結果は何ですか?

x = 8
y = 3
z = 2
result = x * y % z + x // z
print(result)

24. 
次の出力を得るためには、どのようなコードを入力すべきですか?

Name: John, Age: 25

25. 
次のコードを実行した場合の出力は何ですか?

x = 15
y = 2
z = 3
result = x / y * z + z // y - x % z
print(result)

26. 
次の出力を得るためには、どのようなコードを入力すべきですか?

Total: $123.46

27. 
次のコードについて、正しい説明はどれですか?

filter_even = lambda x: x % 2 == 0
print(filter_even(5))

28. 
次のコードの出力結果は何ですか?

x = 9
y = 4
result = x % y + (x // y) * y
print(result)

29. 
次のコードの出力結果は何ですか?

print("The result is {0:.1f}".format(10 / 3))

30. 
次のコードについて、正しい出力を選んでください。

class Parent:
pass

class Child(Parent):
pass

obj = Child()
print(isinstance(obj, Parent))

31. 
次のコードの実行結果を選んでください。

class MyClass:
def __init__(self, x, y):
self.x = x
self.y = y

def add(self):
return self.x + self.y

obj = MyClass(3, 7)
print(obj.add())

32. 
次のコードを実行した場合、出力は何ですか?

from collections import deque
dq = deque([1, 2, 3], maxlen=3)
dq.append(4)
print(dq)

33. 
次のコードを実行した場合、出力は何ですか?

from collections import deque
dq = deque([1, 2, 3], maxlen=3)
dq.extend([4, 5])
print(dq)

34. 
次のコードについて、typeとisinstanceの違いに関する正しい説明を選んでください。

class Parent:
pass

class Child(Parent):
pass

obj = Child()
print(type(obj) == Parent)
print(isinstance(obj, Parent))

35. 
次のコードの実行結果を選んでください。

class MyClass:
def __init__(self, value):
self.value = value

def double(self):
self.value *= 2

obj = MyClass(5)
obj.double()
print(obj.value)

36. 
次のコードの出力結果は何ですか?

print("Coordinates: ({}, {})".format(23.456, 45.678))

37. 
次の出力を得るためには、どのようなコードを入力すべきですか?

Number: 1.23e+02

38. 
次の出力を得るためには、どのようなコードを入力すべきですか?

Aligned: text

39. 
次のコードを実行したときの出力結果は何でしょうか?

filter_even = lambda x: list(filter(lambda n: n % 2 == 0, x))
print(filter_even([1, 2, 3, 4, 5, 6]))

40. 
次のコードの出力結果は何ですか?

price = 19.99
print("The price is ${:.2f}".format(price))

コメントを残すにはログインしてください。