Python 3エンジニア認定基礎試験~模擬試験④~ 2024年12月10日2024年12月10日 ailearn 1. 次のコードの出力結果は何ですか? a = 2b = 4print(a ** b) 8 16 4 6 None 2. 次のコードを実行した場合の出力は何ですか? a = 10b = 3result = a ** b % (a - b)print(result) 6 1 3 10 None 3. 次のコードについて、インスタンスメソッドの正しい説明を選んでください。 class MyClass:def greet(self):return "Hello!" インスタンスメソッドは、インスタンスを通じて呼び出されるクラスの関数である インスタンスメソッドは、クラス全体に関連する処理を行う インスタンスメソッドは、インスタンス変数を変更できない インスタンスメソッドは、クラス名を通じてのみ呼び出される None 4. 次のコードを実行した場合、出力は何ですか? 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 5. 次のコードの説明として正しいものはどれですか? add = lambda x, y: x + yprint(add(5, 3)) 関数addを定義している。 無名関数lambdaを使用して関数addを定義している。 文法エラーが発生する。 Pythonではlambdaをサポートしていない。 None 6. 次のコードを実行した場合、出力は何ですか? 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 7. 次のコードの出力は何でしょうか? 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 8. 次のコードの出力は何ですか? values = [1, 2, 3]values.extend([4, 5, 6])print(values) [1, 2, 3, 4, 5, 6] [1, 2, 3, [4, 5, 6]] [1, 2, 3, 4] Error None 9. 次のコードを実行したときの出力結果は何でしょうか? repeat = lambda s, n: s * nprint(repeat("A", 3)) AAA A3 3A 333 None 10. 次のコードを実行したときの出力結果は何でしょうか? add = lambda x, y=10: x + yprint(add(5)) 5 10 15 エラー None 11. 次の出力を得るためには、どのようなコードを入力すべきですか? 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 12. 次のコードの出力結果は何ですか? x = 17y = 5print(x % y) 2 3 7 5 None 13. 次のコードを実行したときの出力結果は何でしょうか? power = lambda x, y: x ** yprint(power(2, 3)) 6 8 9 エラー None 14. 次のコードの出力結果は何ですか? print("Coordinates: ({}, {})".format(23.456, 45.678)) Coordinates: (23, 45) Coordinates: (23.46, 45.68) Coordinates: (23.456, 45.678) Coordinates: ({}, {}) None 15. 次のコードの実行結果を選んでください。 class A:passclass B(A):passclass C:passprint(issubclass(B, (A, C))) True False エラーが発生する None None 16. 次のコードを実行したときの出力結果は何でしょうか? 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 17. 次のコードの出力結果は何ですか? a = 8b = 3c = 5result = a // b + b * c - a % cprint(result) 14 13 15 12 None 18. 次のコードの出力結果は何ですか? 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 19. 次のコードの実行結果を選んでください。 class A:passclass B:passprint(issubclass(A, (A, B))) True False エラーが発生する None None 20. 次のコードを実行したときの出力結果は何でしょうか? reverse_concat = lambda s1, s2: s2 + s1print(reverse_concat("Hello", "World")) HelloWorld WorldHello Hello World エラー None 21. 次のコードの出力は何でしょうか? lst = [1, [2, 3], [4, 5, [6, 7]], 8]print(lst[2][2][1]) 5 6 7 Error None 22. 次のコードの実行結果を選んでください。 class A:passclass B(A):passclass C(A):passobj = B()print(isinstance(obj, C)) True False エラーが発生する None None 23. 次のコードの出力結果は何ですか? x = 20y = 4z = 3result = x % y + z ** y // xprint(result) 1 3 4 5 None 24. 次のコードを実行した場合、出力は何ですか? from collections import dequedq = deque(maxlen=5)dq.extend([1, 2, 3])dq.extendleft([4, 5])print(dq) deque([1, 2, 3, 4, 5]) deque([4, 5, 3, 2, 1]) エラー deque([5, 4, 1, 2, 3]) None 25. 次のコードを実行した場合、出力は何ですか? from collections import dequedq = deque([1, 2, 3])dq.clear()print(dq) deque([]) [] None エラー None 26. 次の出力を得るためには、どのようなコードを入力すべきですか? 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 27. 次のコードの実行結果を選んでください。 class A:passclass B(A):passclass C:passprint(isinstance(B(), A))print(isinstance(C(), A)) True False True True False False エラーが発生する None 28. Pythonで文字列の書式指定に使用するメソッドとして正しいものはどれですか? join() format() split() replace() None 29. 次の出力を得るためには、どのようなコードを入力すべきですか? Percentage: 75.0% print("Percentage: {:.1%}".format(0.75)) print("Percentage: {:.1}".format(75)) print("Percentage: {:0.1%}".format(75)) print("Percentage: {:.1f}".format(0.75)) None 30. 次のコードを実行した場合、出力は何ですか? from collections import dequedq = deque([1, 2, 3, 4], maxlen=4)dq.append(5)print(dq) deque([1, 2, 3, 4]) deque([5, 2, 3, 4]) deque([2, 3, 4, 5]) エラー None 31. 次のコードについて、typeとisinstanceの違いに関する正しい説明を選んでください。 class Parent:passclass Child(Parent):passobj = Child()print(type(obj) == Parent)print(isinstance(obj, Parent)) 両方とも正確なクラスのみを判定する isinstanceはクラス名を文字列として受け取る typeは正確なクラスを判定し、isinstanceは継承関係を考慮する typeは継承関係を考慮する None 32. 次のコードの出力は何でしょうか? 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 33. 次のコードの実行結果を選んでください。 class A:passclass B(A):passclass C(B):passprint(isinstance(C(), (A, B))) エラーが発生する False True None None 34. 次のコードの出力結果は何ですか? x = 10y = 3z = 4result = (x + y * z) % (x - y)print(result) 4 2 1 3 None 35. 次のコードを実行した場合、出力は何ですか? from collections import dequedq = deque(maxlen=3)dq.append(1)dq.append(2)dq.extend([3, 4])print(dq) deque([1, 2, 3]) deque([1, 3, 4]) deque([2, 3, 4]) deque([3, 4]) None 36. 次のコードの実行結果を選んでください。 class MyClass:def __init__(self, x):self.x = xobj1 = MyClass(10)obj2 = MyClass(20)print(obj1.x + obj2.x) 30 20 10 エラーが発生する None 37. 次のコードの出力結果は何ですか? name = "Alice"print("Hello, {}!".format(name)) Hello, Alice! Hello, {}! Hello, name! Hello, ! None 38. 次の出力を得るためには、どのようなコードを入力すべきですか? Value: 0050 print("Value: {:04}".format(50)) print("Value: {:02}".format(50)) print("Value: {}".format(50)) print("Value: {:05}".format(50)) None 39. 次のコードについて、インスタンスを生成する方法として正しいものを選んでください。 class MyClass:pass obj = MyClass obj = MyClass() obj = new MyClass() obj = MyClass.create() None 40. 次の出力を得るためには、どのようなコードを入力すべきですか? 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 Time's up