Python 3エンジニア認定基礎試験~模擬試験③~ 2024年12月10日2024年12月10日 ailearn 1. 3.14159を小数点以下2桁まで表示するにはどれを使いますか? round(3.14159, 2) math.ceil(3.14159) int(3.14159) float("3.14") None 2. 次のコードを実行したときの出力結果は何でしょうか? def build_profile(first_name, last_name, age=25, country="Japan"):return f"{first_name} {last_name}, {age} years old, from {country}"print(build_profile("Tom", "Smith", country="USA")) Tom Smith, 25 years old, from Japan エラー Tom Smith, None years old, from USA Tom Smith, 25 years old, from USA None 3. 次のコードにおいて、finallyブロックの役割として正しいものを選んでください。 try:x = 10 / 0except ZeroDivisionError:print("Cannot divide by zero")finally:print("Execution complete") tryブロック内の例外が発生した場合でも必ず実行されるコード 例外が発生しない場合のみ実行されるコード 例外をキャッチして処理を行うコード 例外を発生させるコード None 4. 次のコードを実行したときの出力結果は何でしょうか? def order_summary(item, quantity=1, price=100):total = quantity * pricereturn f"Order: {item}, Quantity: {quantity}, Total: {total}"print(order_summary("Notebook", quantity=2)) Order: Notebook, Quantity: 2, Total: 200 Order: Notebook, Quantity: 1, Total: 100 Order: Notebook, Quantity: 1, Total: 200 エラー None 5. 次のコードを実行したときの出力結果は何でしょうか? def customize_greeting(name="Guest", greeting="Welcome"):return f"{greeting}, {name}!"print(customize_greeting(greeting="Hello")) Hello, Guest! Welcome, Guest! Hello, Guest. エラー None 6. divmod(10, 3)の出力結果はどれですか? (3, 0) (3, 3) (3, 2) (3, 1) None 7. 次のコードについて、クラスメソッドを定義する方法として正しいものを選んでください。 class MyClass:@???def my_class_method(cls):print("This is a class method") staticmethod initmethod classmethod classmethods None 8. 次のコードを実行した場合の出力は何ですか? s = "abcdefghij"print(s[2:8:2]) cdefgh cdefg ceg cfh None 9. 次のコードを実行したときの出力結果は何でしょうか? def describe_item(name, price=100, stock=10):return f"Item: {name}, Price: {price}, Stock: {stock}"print(describe_item("Notebook", stock=5)) Item: Notebook, Price: 100, Stock: 10 Item: Notebook, Price: 100, Stock: 5 Item: Notebook, Price: 100, Stock: None エラー None 10. 次のコードを実行した場合の出力は何ですか? s = "abcdefghij"print(s[2:9:3]) cfh cfi ceg ch None 11. デフォルト値を持つ引数の順序に関する正しい説明はどれですか? デフォルト値を持つ引数は任意の位置に配置できる。 デフォルト値を持たない引数の後に配置する必要がある。 デフォルト値を持つ引数は常に関数の最後に配置する必要がある。 デフォルト値を持つ引数はキーワード引数としてのみ使用可能である。 None 12. 次のコードの実行結果を選んでください。 class MyClass:@classmethoddef greet(cls):return "Hello from class method"print(MyClass.greet()) エラーが発生する 何も出力されない "Hello from class method" "Hello from instance method" None 13. pow(4, 3, 5)の出力はどれですか? 4 3 2 1 None 14. 次のコードの実行結果を選んでください。 def test_function():try:return "Try block result"finally:return "Finally block result"print(test_function()) エラーが発生してプログラムが停止する "Try block result" "Finally block result" 何も出力されない None 15. 次のコードを実行した場合、結果は何になりますか? def say_hello(name="Guest"):return f"Hello, {name}!"print(say_hello())print(say_hello("Alice")) Hello, Guest! Hello, Guest! Hello, Alice! Hello, Alice! Hello, Guest! Hello, Alice! エラー None 16. 5 // 2の出力結果は何ですか? 2 2.5 3 5 None 17. complex(3, -4).imagの結果はどれですか? 3 4 0 -4 None 18. 次のコードを実行したときの出力結果は何でしょうか? def divide(a, b=1):return a / bprint(divide(10, b=2)) 10 2 エラー 5.0 None 19. round(2.6)の結果はどれですか? 2 2.6 3 エラー None 20. 3進数でint("102", 3)の結果は次のどれですか? 11 10 9 5 None 21. 次のコードを実行したときの出力結果は何でしょうか? def summarize(name, hobby="reading", age=18):return f"{name}, {age} years old, likes {hobby}."print(summarize("Emily", hobby="swimming")) Emily, 18 years old, likes swimming. Emily, 18 years old, likes reading. エラー Emily, None years old, likes swimming. None 22. 次のコードを実行したときの出力結果は何でしょうか? def greet(name, message="Hello"):return f"{message}, {name}!"print(greet("Alice", "Hi")) Hello, Alice! Alice, Hi! Hi, Alice! エラー None 23. 次のコードを実行したときの出力結果は何でしょうか? def sum_numbers(a=1, b=2, c=3):return a + b + cprint(sum_numbers(c=6)) 9 6 3 12 None 24. 次のコードの実行結果を選んでください。 class MyClass:def __init__(self, value):self.value = valuedef double(self):self.value *= 2obj = MyClass(5)obj.double()print(obj.value) None 5 10 エラーが発生する None 25. 次のコードを実行したときの出力結果は何でしょうか? def greet(name, message="Welcome", punctuation="!"):return f"{message}, {name}{punctuation}"print(greet("Alice", punctuation="!!!")) Welcome, Alice!!! Welcome, Alice! Welcome Alice!!! エラー None 26. 次のコードの実行結果を選んでください。 class MyClass:class_attribute = "shared"obj1 = MyClass()obj2 = MyClass()obj1.class_attribute = "modified"print(obj2.class_attribute) "modified" "shared" None エラーが発生する None 27. 次のコードの実行結果を選んでください。 class MyClass:class_variable = 10obj1 = MyClass()obj2 = MyClass()obj1.class_variable = 20print(MyClass.class_variable) 10 20 エラーが発生する None None 28. bin(10)の出力はどれですか? 1010 0b10 0b1010 10 None 29. Pythonで文字列s = "Python Programming"の先頭から10文字を取得するスライスはどれですか? s[0:9] s[10:] s[:10] s[1:10] None 30. 0.2 + 0.1 == 0.3の評価結果はどれですか? True False エラーが発生する None None 31. 次のコードの実行結果を選んでください。 class MyClass:class_variable = "shared"obj = MyClass()MyClass.class_variable = "modified"print(obj.class_variable) "shared" エラーが発生する "modified" None None 32. 文字列s = "abcdefghij"の最初から最後までの文字を取得するスライスはどれですか? s[:] s[0:] s[0:len(s)] すべて正しい None 33. 次のコードを実行したときの出力結果は何でしょうか? def build_profile(name, age=18, country="Japan"):return f"{name}, {age} years old, from {country}"print(build_profile("Tom", country="USA")) Tom, 18 years old, from Japan エラー Tom, None years old, from USA Tom, 18 years old, from USA None 34. 次のコードの実行結果を選んでください。 class MyClass:class_variable = "shared"MyClass.class_variable = "modified"print(MyClass.class_variable) エラーが発生する "shared" "modified" None None 35. abs(-3.7)の結果はどれですか? -3.7 3 0 3.7 None 36. 次のコードについて、正しい説明を選んでください。 class MyClass:class_variable = "shared"obj = MyClass()print(obj.class_variable) クラス変数class_variableの値が出力される インスタンス変数が未定義のためエラーが発生する クラス変数にはインスタンスからアクセスできない 何も出力されない None 37. 次のコードを実行した場合の出力は何ですか? s = "abcdefghij"print(s[3:-3]) defg def defgh d None 38. 文字列s = "abcdefghij"のインデックス1から8までを逆順で取得するために使用するスライスはどれですか? s[8:1:-1] s[8:0:-1] s[7:0:-1] s[-8:-1:-1] None 39. 次のコードを実行したときの出力結果は何でしょうか? def repeat_string(s, times=3, separator=" "):return separator.join([s] * times)print(repeat_string("Hi", times=2)) Hi Hi Hi Hi Hi HiHi エラー None 40. 次のコードに関する正しい説明はどれですか? def greet(name="John", age):return f"{name} is {age} years old." 正常に動作する。 エラーが発生する。 nameに値を指定しない場合、ageが使用されない。 nameとageの順序を入れ替えれば動作する。 None Time's up