Python 3エンジニア認定基礎試験~模擬試験①~ 2024年12月10日2024年12月10日 ailearn 1. 次のコードの出力は何ですか? def func(x, y=10):return x + yprint(func(5))print(func(5, 15)) 15 15 10 15 15 20 15 25 None 2. 次のコードを実行したときの出力結果は何でしょうか? def join_strings(*args):return ", ".join(args)print(join_strings("apple", "banana", "cherry"))print(join_strings("Python", "Java")) "apple, banana, cherry" "Python, Java" "apple, banana" "Python, Java" "apple, banana, cherry" "Python" "apple" "Python, Java" None 3. 次のコードを実行したときの出力結果は何でしょうか? def add_three(a, b, c=1):return a + b + cprint(add_three(2, 3))print(add_three(2, 3, 4)) 5 6 1 5 6 6 6 9 None 4. 次のコードを実行したときの出力結果は何でしょうか? def greet_many(times=1):return "Hello! " * timesprint(greet_many())print(greet_many(3)) Hello! Hello! Hello! Hello! Hello! Hello! Hello! Hello! Hello! Hello! None 5. 次のコードを対話モードで実行した場合の出力は何ですか? 10 / 3 3 3.3333 3.0 4 None 6. 次のコードを実行したときの出力結果は何でしょうか? def increment(number, step=1):return number + stepprint(increment(5))print(increment(5, 2)) 5 7 6 7 5 6 6 5 None 7. 次のコードの実行結果として正しいものを選んでください。 try:result = 10 / 2except ZeroDivisionError:print("Cannot divide by zero")else:print("Result:", result) "Cannot divide by zero" 何も出力されない "Result: 5.0" エラーが発生する None 8. 次のコードの実行結果を選んでください。 try:result = "text" + 5except TypeError as e:print("TypeError occurred:", e) "TypeError occurred" "TypeError occurred: can only concatenate str (not "int") to str" エラーが発生する 何も出力されない None 9. Pythonの対話モードで使用できる「ヘルプ」機能を起動するにはどうすればよいですか? start_help help_start() begin_help() help() None 10. 次のコードの出力は何ですか? for i in range(1, 5):if i == 3:continueprint(i) 1 2 3 4 1 2 4 1 2 1 2 3 None 11. Pythonの「論理演算子」として使用できないものはどれですか? and or xor not None 12. 次のコードを実行したときの出力結果は何でしょうか? def add(a, b=2):return a + bresult1 = add(5)result2 = add(5, 3)print(result1, result2) 7 8 7 5 5 8 7 3 None 13. 次のコードの実行結果を選んでください。 import jsondata = '{"name": "Charlie", "age": 35, "city": "Kyoto"}'parsed_data = json.loads(data)print(parsed_data["city"]) "Charlie" "Kyoto" 35 エラーが発生する None 14. Pythonの対話モードでエラーの詳細な情報を表示するには、何を入力しますか? debug() traceback last_error _ None 15. Pythonの対話モードで「1から10までの整数を降順で表示する」には、どのようなコードを入力すべきですか? range(10, 0, -1) sorted(range(1, 11), reverse=True) reverse(range(1, 11)) range(1, 11, -1) None 16. 2つの文字列を結合して返す関数concatを正しく定義するコードはどれでしょうか? def concat(str1, str2): print(str1 + str2) def concat(str1, str2): return str1 + str2 concat(str1, str2): return str1 + str2 def concat(str1, str2) return str1 + str2 None 17. 次のコードの出力は何ですか? a = "Hello"b = a.replace("H", "J")print(a)print(b) Hello Hello Jello Hello Jello Jello Hello Jello None 18. 次のコードを実行したときの出力結果は何でしょうか? def factorial(n):if n == 0:return 1return n * factorial(n - 1)print(factorial(3))print(factorial(5)) 5 15 3 5 6 120 15 120 None 19. 次のコードを対話モードで実行した場合の出力は何ですか? x = 2y = x ** 3y 6 9 4 8 None 20. 次のコードで、JSON形式のデータをファイルに書き込むために使用する正しい関数を選んでください。 import jsondata = {"name": "Bob", "age": 30, "city": "Osaka"}with open("data.json", "w") as f:??? json.dumps(data) f.write(json.dumps(data)) json.dump(data, f) json.load(f, data) None 21. Pythonのファイル拡張子として正しいものはどれですか? .pyt .py .python .pt None 22. 次のコードを実行したときの出力結果は何でしょうか? def divide(a, b=1):return a / bresult1 = divide(6)result2 = divide(6, 2)print(result1, result2) 6.0 3.0 3 3 6 2 6.0 1.0 None 23. 次のコードを実行したときの出力結果は何でしょうか? def power(base, exponent=2):return base ** exponentprint(power(3))print(power(2, 3)) 6 8 3 4 9 8 8 9 None 24. 次のコードを対話モードで実行した場合の出力は何ですか? x = "Python"x * 3 PythonPythonPython Python3 エラーが発生する PythonPython3 None 25. 次のコードの実行結果として正しいものを選んでください。 try:open("nonexistent_file.txt", "r")except FileNotFoundError:print("File not found")finally:print("Execution complete") File not found Execution complete File not found Execution complete エラーが発生する None 26. 次のコードの出力は何ですか? a = [1, 2, 3]print(a * 2) [2, 4, 6] [1, 1, 2, 2, 3, 3] エラーが発生する [1, 2, 3, 1, 2, 3] None 27. 次のコードを実行したときの出力結果は何でしょうか? def power(base, exponent=2):return base ** exponentprint(power(3))print(power(2, 3)) 6 8 9 8 6 16 9 8 None 28. Pythonの創始者である「グイド・ヴァンロッサム」が、Pythonの開発を始めたきっかけとなったのはどの言語の後継を意識したからですか? Java Perl ABC C++ None 29. 次のコードの実行結果を選んでください。 import jsondata = {"name": "Bob", "age": 30, "city": "Tokyo"}json_data = json.dumps(data)print(type(json_data)) None 30. Pythonの「標準ライブラリ」に含まれていないものはどれですか? os sys pandas math None 31. Pythonの公式ドキュメントや多数のライブラリが提供されているリポジトリはどこですか? GitLab SourceForge GitHub Stack Overflow None 32. 次のコードの実行結果を選んでください。 import jsondata = {"scores": {"Math": 90, "Science": 85}}with open("scores.json", "w") as f:json.dump(data, f, indent=4)with open("scores.json", "r") as f:loaded_data = json.load(f)print(loaded_data["scores"]["Math"]) 85 90 {"Math": 90, "Science": 85} エラーが発生する None 33. 次のコードの実行結果として正しいものを選んでください。 try:x = 10 / 0except ZeroDivisionError:print("Division by zero")except Exception:print("General exception") "General exception" "Division by zero" 両方のメッセージが出力される エラーが発生する None 34. Pythonの標準ライブラリを使用して、JSONデータを読み書きするためにインポートする必要があるモジュールを選んでください。 json pickle csv yaml None 35. 次のコードの実行結果を選んでください。 import jsondata = {"name": "Frank", "hobbies": ["reading", "traveling", "coding"]}with open("hobbies.json", "w") as f:json.dump(data, f, indent=2) ファイルhobbies.jsonが作成され、整形されたJSONデータが保存される ファイルhobbies.jsonが作成され、1行でJSONデータが保存される エラーが発生する ファイルが作成されない None 36. 対話モードで次の行を続けて書く必要があるときに使用する記号はどれですか? : ; ¥ / None 37. 次のコードの実行結果を選んでください。 import jsonjson_data = '{"key": null}'data = json.loads(json_data)print(data["key"] is None) null エラーが発生する True False None 38. 次のコードの実行結果として正しいものを選んでください。 try:x = int("123")except ValueError:print("Invalid value")else:print("Conversion successful:", x)finally:print("End of program") Invalid value End of program 123 End of program エラーが発生する Conversion successful: 123 End of program None 39. Pythonの主な特徴の1つとして、以下のうち正しい説明はどれですか? Pythonは静的型付け言語である Pythonはインタプリタ型の言語である Pythonはメモリ管理をユーザーが行う Pythonはマルチスレッドをサポートしない None 40. 次のコードの実行結果を選んでください。 import jsondata = {"numbers": [1, 2, 3, 4, 5]}with open("numbers.json", "w") as f:json.dump(data, f)with open("numbers.json", "r") as f:loaded_data = json.load(f)print(loaded_data["numbers"][-1]) 1 3 5 エラーが発生する None Time's up