Python 3エンジニア認定基礎試験~模擬試験④~ 2024年12月10日2024年12月10日 ailearn 1. 次のコードを実行したときの出力結果は何でしょうか? square_diff = lambda x, y: (x - y) ** 2print(square_diff(7, 5)) 2 8 4 16 None 2. 次のコードの出力は何でしょうか? data = [[1, 2], [3, 4], [5, 6]]result = [x[0] for x in data]print(result) [2, 4, 6] [1, 2, 3, 4, 5, 6] [1, 3, 5] Error None 3. 次のコードについて、正しい説明はどれですか? filter_even = lambda x: x % 2 == 0print(filter_even(5)) 偶数かどうかを判定し、TrueまたはFalseを返す。 偶数の場合は数値を返し、奇数の場合はNoneを返す。 文法エラーが発生する。 無名関数では偶数判定はできない。 None 4. 次のコードの実行結果を選んでください。 class A:passclass B:passprint(issubclass(A, (A, B))) True False エラーが発生する None None 5. 次のコードの出力結果は何ですか? print("Coordinates: ({}, {})".format(23.456, 45.678)) Coordinates: (23, 45) Coordinates: (23.46, 45.68) Coordinates: (23.456, 45.678) Coordinates: ({}, {}) None 6. 次のコードを実行した場合、出力は何ですか? from collections import dequedq = deque([1, 2, 3])dq.extend([4, 5])print(dq) deque([1, 2, 3, 4, 5]) deque([4, 5, 1, 2, 3]) [1, 2, 3, 4, 5] エラー None 7. 次のコードの出力は何でしょうか? fruits = ['apple', 'banana', 'cherry']print(fruits[-2]) 'apple' 'banana' 'cherry' IndexError None 8. 次のコードの実行結果を選んでください。 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 9. 次のコードを実行した場合、出力は何ですか? from collections import dequedq = deque([1, 2, 3])x = dq.popleft()y = dq.pop()print(dq) deque([1]) deque([2]) deque([]) deque([2, 3]) None 10. 次のコードを実行した場合、出力は何ですか? from collections import dequedq = deque([1, 2, 3, 4])dq.extendleft([5, 6])print(dq) deque([5, 6, 1, 2, 3, 4]) deque([4, 3, 2, 1, 6, 5]) deque([6, 5, 1, 2, 3, 4]) deque([1, 2, 3, 4, 5, 6]) None 11. 次のコードの出力結果は何ですか? x = 10y = 3print(x + y) 7 10 13 30 None 12. 次のコードについて、正しい説明を選んでください。 class A:passclass B(A):passclass C(B):passobj = C()print(isinstance(obj, A)) Falseが出力される Trueが出力される エラーが発生する Noneが出力される None 13. 次のコードの出力は何でしょうか? nums = [1, 2, 3, 4, 5]nums = [x * 2 for x in nums if x % 2 == 1]print(nums) [1, 3, 5] [2, 4, 6, 8, 10] [2, 6, 10] [2, 6, 4] None 14. 次の出力を得るためには、どのようなコードを入力すべきですか? Temperature: 23.5°C print("Temperature: {:.2f}°C".format(23.456)) print("Temperature: {:.1f} °C".format(23.4)) print("Temperature: {:.1f}°C".format(23.456)) print("Temperature: {:.0f}°C".format(23.456)) None 15. 次のコードを実行した場合の出力は何ですか? multiply = lambda x, y: x * yprint(multiply(3, 4)) 7 34 エラー 12 None 16. 次のコードの実行結果を選んでください。 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 17. 次のコードの実行結果を選んでください。 class MyClass:def __init__(self, value):self.value = valueobj = MyClass(5)print(obj.value)obj.value = 10print(obj.value) 5 5 5 10 エラーが発生する 何も出力されない None 18. 次のコードの実行結果を選んでください。 class A:passclass B(A):passclass C:passprint(isinstance(B(), A))print(isinstance(C(), A)) True False True True False False エラーが発生する None 19. 次のコードの実行結果を選んでください。 class A:passclass B(A):passclass C(B):passprint(isinstance(C(), (A, B))) エラーが発生する False True None None 20. 次のコードの出力結果は何ですか? language = "Python"version = 3print("I am learning {0} {1}.".format(language, version)) I am learning Python 3. I am learning {0} {1}. I am learning language version. I am learning Python. None 21. 次のコードの実行結果を選んでください。 class MyClass:def __init__(self, x):self.x = xobj1 = MyClass(10)obj2 = MyClass(20)print(obj1.x + obj2.x) 30 20 10 エラーが発生する None 22. 次のコードについて、インスタンスの正しい説明を選んでください。 class MyClass:passobj = MyClass() objはMyClassクラスのインスタンスである objはクラスそのものである objはMyClassクラスのメソッドである objは定義されていない None 23. 次のコードを実行した場合、出力は何ですか? from collections import dequedq = deque([1, 2, 3])dq.pop()print(dq) deque([1, 2]) deque([2, 3]) deque([1]) エラー None 24. 次のコードの出力は何でしょうか? 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 25. 次のコードの出力は何でしょうか? 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 26. 次のコードを実行した場合、出力は何ですか? from collections import dequedq = deque([1, 2, 3])dq.append(4)print(dq) deque([1, 2, 3, 4]) [1, 2, 3, 4] [4, 1, 2, 3] deque([4, 1, 2, 3]) None 27. 次のコードの出力結果は何ですか? a = 7b = 2print(a / b * b) 3.5 2.0 7.0 1.0 None 28. 次のコードの実行結果を選んでください。 class MyClass:def __init__(self, value):self.value = valuedef double(self):self.value *= 2obj = MyClass(5)obj.double()print(obj.value) 5 10 0 エラーが発生する None 29. 次のコードを実行したときの出力結果は何でしょうか? 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 30. 次のコードの出力として正しいものはどれですか? increment = lambda x: x + 1print(increment(10)) 11 10 エラー None None 31. 次のコードの出力結果は何ですか? x = 20y = 4z = 3result = x % y + z ** y // xprint(result) 1 3 4 5 None 32. 次の出力を得るためには、どのようなコードを入力すべきですか? Binary: 1101 print("Binary: {:b}".format(13)) print("Binary: {}".format(bin(13))) print("Binary: {:b}".format(13)) と print("Binary: {}".format(bin(13))) print("Binary: {:B}".format(13)) None 33. 次のコードについて、typeとisinstanceの違いに関する正しい説明を選んでください。 class Parent:passclass Child(Parent):passobj = Child()print(type(obj) == Parent)print(isinstance(obj, Parent)) 両方とも正確なクラスのみを判定する isinstanceはクラス名を文字列として受け取る typeは正確なクラスを判定し、isinstanceは継承関係を考慮する typeは継承関係を考慮する None 34. 次のコードについて、インスタンスメソッドの正しい使い方を選んでください。 class MyClass:def __init__(self, name):self.name = namedef greet(self):return f"Hello, {self.name}!" print(MyClass.greet("Alice")) obj = MyClass("Alice"); print(obj.greet()) obj = MyClass("Alice"); print(MyClass.greet(obj)) print(MyClass.greet()) None 35. 次のコードの出力結果は何ですか? a = 15b = 4print(a - b) 11 19 -11 4 None 36. 次の出力を得るためには、どのようなコードを入力すべきですか? Value: +123 print("Value: {:+}".format(123)) print("Value: {}".format(123)) print("Value: {: }".format(123)) print("Value: {:-}".format(123)) None 37. 次のコードを実行した場合、出力は何ですか? from collections import dequedq = deque([1, 2, 3])dq.appendleft(0)print(dq) deque([1, 2, 3, 0]) deque([0, 1, 2, 3]) [1, 2, 3, 0] [0, 1, 2, 3] None 38. 次のうち、collections.dequeについて正しい説明はどれですか? dequeはリストと同じで、末尾の操作が高速です。 dequeはリストよりも両端の操作が高速です。 dequeはスタック操作に特化しており、キューとしては使用できません。 dequeはPython 3.10で導入されました。 None 39. 次のコードを実行したときの出力結果は何でしょうか? calculate = lambda x, y: x * y if x > y else x + yprint(calculate(3, 5)) 8 15 5 3 None 40. 次のコードの実行結果を選んでください。 class MyClass:def __init__(self, value):self.value = valuedef reset(self):self.value = 0obj = MyClass(10)obj.reset()print(obj.value) 10 0 エラーが発生する None None Time's up