Python 3エンジニア認定基礎試験~模擬試験④~ 2024年12月10日2024年12月10日 ailearn 1. 次のコードの出力は何でしょうか? data = [10, 20, 30, 40, 50]data[1:4] = [15, 25]print(data) [10, 15, 25, 50] [10, 15, 25, 40, 50] [15, 25, 30, 40, 50] Error None 2. 次のコードの出力は何でしょうか? numbers = [1, 2, 3, 4, 5]numbers.insert(-1, 10)print(numbers) [1, 2, 3, 4, 5, 10] [1, 2, 3, 4, 10, 5] [10, 1, 2, 3, 4, 5] Error None 3. 次のコードを実行したときの出力結果は何でしょうか? filter_even = lambda x: list(filter(lambda n: n % 2 == 0, x))print(filter_even([1, 2, 3, 4, 5, 6])) [2, 4, 6] [1, 3, 5] エラー [1, 2, 3, 4, 5, 6] None 4. 次のコードの実行結果を選んでください。 class MyClass:def __init__(self, items):self.items = itemsobj = MyClass([1, 2, 3])obj.items.append(4)print(obj.items) [1, 2, 3, 4] [1, 2, 3] エラーが発生する None None 5. 次のコードの出力は何になるでしょうか? a = [1, 2, 3]b = ab.append(4)print(a) [1, 2, 3] [1, 2, 3, 4] [1, 2, 4] Error None 6. 以下のコードの出力は何でしょうか? a = [1, 2, 3]b = [4, 5]print(a + b) [1, 2, 3, 4, 5] [5, 4, 3, 2, 1] [[1, 2, 3], [4, 5]] Error None 7. 次のコードを実行したときの出力結果は何でしょうか? repeat = lambda s, n: s * nprint(repeat("A", 3)) AAA A3 3A 333 None 8. Pythonのリストに対して適切な操作を行い、最初の要素を取得するにはどうすればよいでしょうか? numbers = [10, 20, 30, 40]# 最初の要素を取得 numbers[1] numbers[-1] numbers[0] numbers.first() None 9. 次のコードを実行した場合、出力は何ですか? from collections import dequedq = deque(["a", "b", "c"])dq.appendleft("z")print(dq) deque(['z', 'a', 'b', 'c']) エラー ['z', 'a', 'b', 'c'] deque(['a', 'b', 'c', 'z']) None 10. 次のコードの出力は何でしょうか? nums = [1, 2, 3, 4, 5, 6]nums[1:5:2] = [7, 8]print(nums) [1, 7, 3, 8, 5, 6] [1, 7, 8, 4, 5, 6] [1, 7, 3, 8, 6, 5] Error None 11. 次のコードを実行した場合、出力は何ですか? from collections import dequedq = deque([1, 2, 3], maxlen=3)dq.append(4)print(dq) deque([1, 2, 3]) deque([4]) deque([2, 3, 4]) エラー None 12. 次のコードの出力結果は何ですか? a = 10b = 3print(a // b) 3.33 10 0 3 None 13. 次のコードを実行した場合、出力は何ですか? from collections import dequedq = deque([1, 2, 3], maxlen=3)dq.extend([4, 5])print(dq) deque([4, 5]) deque([3, 4, 5]) エラー deque([1, 2, 3, 4, 5]) None 14. 次のコードの実行結果を選んでください。 class MyClass:def __init__(self):self.count = 0def increment(self):self.count += 1obj = MyClass()obj.increment()obj.increment()print(obj.count) エラーが発生する 0 1 2 None 15. 次のコードの実行結果を選んでください。 class MyClass:def __init__(self, name):self.name = namedef greet(self):return f"Hello, {self.name}!"obj = MyClass("Alice")print(obj.greet()) "Alice" "Hello!" "Hello, Alice!" エラーが発生する None 16. 次のコードの出力を選択してください。 a = [1, 2, 3]b = a.copy()b.append(4)print(a) [1, 2, 3] [1, 2, 3, 4] [4] Error None 17. 次のコードを実行したときの出力結果は何でしょうか? triple_map = lambda x: list(map(lambda y: y * 3, x))print(triple_map([1, 2, 3])) エラー [1, 2, 3] [3, 6, 9] [3, 3, 3] None 18. 次のコードの出力結果は何ですか? a = 14b = 5result = (a * b) % (b - a // b)print(result) 0 2 4 1 None 19. 次のコードの実行結果を選んでください。 class A:passclass B(A):passclass C(B):passobj = C()print(issubclass(type(obj), A)) False True エラーが発生する None None 20. 次のコードの出力結果は何ですか? print("Coordinates: ({}, {})".format(23.456, 45.678)) Coordinates: (23, 45) Coordinates: (23.46, 45.68) Coordinates: (23.456, 45.678) Coordinates: ({}, {}) None 21. 次のコードの出力結果は何ですか? print("The result is {0:.1f}".format(10 / 3)) The result is 3.33 The result is 3 The result is 3.333 The result is 3.3 None 22. 次のコードの出力は何でしょうか? numbers = [1, 2, 3, 4, 5]print(numbers[::-1]) [1, 2, 3, 4, 5] [5, 4, 2, 3, 1] Error [5, 4, 3, 2, 1] None 23. 次のコードの出力結果は何ですか? x = 10y = 3z = 4result = (x + y * z) % (x - y)print(result) 4 2 1 3 None 24. 次のコードの出力結果は何ですか? a = 7b = 2print(a / b * b) 3.5 2.0 7.0 1.0 None 25. 次のコードについて、正しい出力を選んでください。 class MyClass:passobj = MyClass()print(isinstance(obj, MyClass)) True False エラーが発生する None None 26. リストvalues = [5, 3, 8, 1, 9]を昇順にソートするにはどうすればよいでしょうか? values.sorted() values.sort() sort(values) sorted(values) None 27. 次のコードについて、正しい出力を選んでください。 class Parent:passclass Child(Parent):passobj = Child()print(isinstance(obj, Parent)) False True エラーが発生する None None 28. 次のコードを実行したときの出力結果は何でしょうか? mod = lambda x, y: x % yprint(mod(10, 3)) 1 2 3 4 None 29. 次のコードの実行結果を選んでください。 class MyClass:def __init__(self, values):self.values = valuesobj = MyClass([1, 2, 3])obj.values[0] = 10print(obj.values) [10, 2, 3] [1, 2, 3] エラーが発生する None None 30. 次のコードの出力結果は何ですか? x = 9y = 4result = x % y + (x // y) * yprint(result) 13 9 1 4 None 31. 次のコードの実行結果を選んでください。 class A:passclass B(A):passobj = B()print(type(obj) == A) True False エラーが発生する None None 32. 次のコードの出力結果は何ですか? name = "Alice"print("Hello, {}!".format(name)) Hello, Alice! Hello, {}! Hello, name! Hello, ! None 33. 次の出力を得るためには、どのようなコードを入力すべきですか? Total: $123.46 print("Price: ${:.2f}".format(123.456)) print("Price: ${:.1f}".format(123.456)) print("Price: ${}".format(123.46)) print("Price: {:.2f}".format(123.456)) None 34. 次のコードについて、インスタンス変数の変更方法として正しいものを選んでください。 class MyClass:def __init__(self, value):self.value = value self.value = 10 obj = MyClass().value = 10 MyClass.value = 10 obj.value = 10 None 35. 次のコードの実行結果を選んでください。 class MyClass:def __init__(self, x, y):self.x = xself.y = ydef add(self):return self.x + self.yobj = MyClass(3, 7)print(obj.add()) 1 7 3 10 None 36. 次のコードの実行結果を選んでください。 class A:passclass B(A):passclass C(A):passobj = B()print(isinstance(obj, C)) True False エラーが発生する None None 37. 次のコードの実行結果を選んでください。 class Base:passclass Derived(Base):passobj = Derived()print(isinstance(obj, Derived))print(isinstance(obj, Base)) True True True False False True False False None 38. 次のコードで、変数x = 10を埋め込んで「Value: 10」と出力するための正しい記述はどれですか? print("Value: {0}".format(x)) print("Value: {x}") print("Value: {0}".format()) print("Value: {} None 39. 次の出力を得るためには、どのようなコードを入力すべきですか? Name: John, Age: 25 print("Name: {0}, Age: {1}".format("John", 25)) print("Name: {}, Age: {}".format("John", 25)) print("Name: {name}, Age: {age}".format(name="John", age=25)) すべて正しい None 40. Pythonで文字列の書式指定に使用するメソッドとして正しいものはどれですか? join() format() split() replace() None Time's up