Python 3エンジニア認定基礎試験~模擬試験④~ 2024年12月10日2024年12月10日 ailearn 1. リストvalues = [5, 3, 8, 1, 9]を昇順にソートするにはどうすればよいでしょうか? values.sorted() values.sort() sort(values) sorted(values) None 2. 次のコードの出力結果は何ですか? a = 20b = 4result = a // b + a % (b + 1) * a / bprint(result) 10.0 15.0 25.0 5.0 None 3. 次のコードについて、インスタンスの正しい説明を選んでください。 class MyClass:passobj = MyClass() objはMyClassクラスのインスタンスである objはクラスそのものである objはMyClassクラスのメソッドである objは定義されていない None 4. 次のコードの実行結果を選んでください。 class MyClass:def __init__(self, name):self.name = nameobj = MyClass("Bob")del obj.nameprint(obj.name) "Bob" None "" エラーが発生する None 5. 次のコードの実行結果を選んでください。 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 6. 次のコードについて、インスタンス変数の変更方法として正しいものを選んでください。 class MyClass:def __init__(self, value):self.value = value self.value = 10 obj = MyClass().value = 10 MyClass.value = 10 obj.value = 10 None 7. 次のコードの出力は何でしょうか? 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 8. 次のコードについて、正しい出力を選んでください。 class MyClass:passobj = MyClass()print(isinstance(obj, MyClass)) True False エラーが発生する None None 9. 次のコードの出力は何でしょうか? fruits = ['apple', 'banana', 'cherry']print(fruits[-2]) 'apple' 'banana' 'cherry' IndexError None 10. 次のコードを実行した場合の出力は何ですか? multiply = lambda x, y: x * yprint(multiply(3, 4)) 7 34 エラー 12 None 11. 次のコードで、変数x = 10を埋め込んで「Value: 10」と出力するための正しい記述はどれですか? print("Value: {0}".format(x)) print("Value: {x}") print("Value: {0}".format()) print("Value: {} None 12. 次のコードの実行結果を選んでください。 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 13. 次のコードを実行した場合、出力は何ですか? 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 14. 次のコードを実行した場合の出力は何ですか? subtract = lambda x, y=5: x - yprint(subtract(10)) 5 15 -5 エラー None 15. 次のコードを実行したときの出力結果は何でしょうか? square_diff = lambda x, y: (x - y) ** 2print(square_diff(7, 5)) 2 8 4 16 None 16. 次のコードの実行結果を選んでください。 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 17. 次のコードの出力結果は何ですか? a = 15b = 4print(a - b) 11 19 -11 4 None 18. 次のコードを実行した場合の出力は何ですか? a = 10b = 3result = a ** b % (a - b)print(result) 6 1 3 10 None 19. 次の出力を得るためには、どのようなコードを入力すべきですか? 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 20. 次のコードの出力は何でしょうか? numbers = [2, 4, 6, 8]result = [x ** 2 for x in numbers if x % 4 == 0]print(result) [4, 16, 36, 64] [16] [16, 64] [4, 16] None 21. 次のコードを実行した場合、出力は何ですか? 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 22. 次のコードの出力として正しいものはどれですか? double = lambda x: x * 2print(double(double(2))) 4 16 8 エラー None 23. 次のコードの出力結果は何ですか? x = 8y = 3z = 2result = x * y % z + x // zprint(result) 8 4 3 6 None 24. 次の出力を得るためには、どのようなコードを入力すべきですか? 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 25. 次のコードを実行した場合の出力は何ですか? x = 15y = 2z = 3result = x / y * z + z // y - x % zprint(result) 20.5 21.0 23.5 18.0 None 26. 次の出力を得るためには、どのようなコードを入力すべきですか? 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 27. 次のコードについて、正しい説明はどれですか? filter_even = lambda x: x % 2 == 0print(filter_even(5)) 偶数かどうかを判定し、TrueまたはFalseを返す。 偶数の場合は数値を返し、奇数の場合はNoneを返す。 文法エラーが発生する。 無名関数では偶数判定はできない。 None 28. 次のコードの出力結果は何ですか? x = 9y = 4result = x % y + (x // y) * yprint(result) 13 9 1 4 None 29. 次のコードの出力結果は何ですか? 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 30. 次のコードについて、正しい出力を選んでください。 class Parent:passclass Child(Parent):passobj = Child()print(isinstance(obj, Parent)) False True エラーが発生する None None 31. 次のコードの実行結果を選んでください。 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 32. 次のコードを実行した場合、出力は何ですか? 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 33. 次のコードを実行した場合、出力は何ですか? 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 34. 次のコードについて、typeとisinstanceの違いに関する正しい説明を選んでください。 class Parent:passclass Child(Parent):passobj = Child()print(type(obj) == Parent)print(isinstance(obj, Parent)) 両方とも正確なクラスのみを判定する isinstanceはクラス名を文字列として受け取る typeは正確なクラスを判定し、isinstanceは継承関係を考慮する typeは継承関係を考慮する None 35. 次のコードの実行結果を選んでください。 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 36. 次のコードの出力結果は何ですか? print("Coordinates: ({}, {})".format(23.456, 45.678)) Coordinates: (23, 45) Coordinates: (23.46, 45.68) Coordinates: (23.456, 45.678) Coordinates: ({}, {}) None 37. 次の出力を得るためには、どのようなコードを入力すべきですか? Number: 1.23e+02 print("Number: {:.3f}".format(123.45)) print("Number: {:.2f}".format(123.45)) print("Number: {:.1f}".format(123.45)) print("Number: {:.2e}".format(123.45)) None 38. 次の出力を得るためには、どのようなコードを入力すべきですか? Aligned: text print("Aligned: {:10}".format("text")) print("Aligned: {:<10}".format("text")) print("Aligned: {:^10}".format("text")) print("Aligned: {:>10}".format("text")) None 39. 次のコードを実行したときの出力結果は何でしょうか? 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 40. 次のコードの出力結果は何ですか? price = 19.99print("The price is ${:.2f}".format(price)) The price is $19 The price is $19.990 The price is $20 The price is $19.99 None Time's up