Python 3エンジニア認定基礎試験~模擬試験①~ 2024年12月10日2024年12月10日 ailearn 1. 次のコードの実行結果を選んでください。 try:raise ValueError("Invalid input")except ValueError as e:print("Caught exception:", e) 何も出力されない エラーが発生する "ValueError: Invalid input" "Caught exception: Invalid input" None 2. 次のコードの実行結果を選んでください。 try:x = int("10.5")except ValueError:print("Conversion failed") "Conversion failed" 10 10.5 エラーが発生する None 3. 次のコードを実行したときの出力結果は何でしょうか? def format_text(text, prefix="*", suffix="*"):return prefix + text + suffixprint(format_text("Hello"))print(format_text("Hello", prefix="~"))print(format_text("Hello", suffix="?")) *Hello* ~Hello~ *Hello? *Hello* ~Hello* Hello? *Hello* ~Hello* *Hello? Hello* *Hello? ~Hello~ None 4. 次のコードの実行結果を選んでください。 try:raise RuntimeError("Unexpected error")except RuntimeError as e:print("Caught runtime error:", e) "Caught runtime error: Unexpected error" "RuntimeError: Unexpected error" エラーが発生する 何も出力されない None 5. 次のコードの実行結果を選んでください。 import jsonjson_data = '{"name": "Alice", "skills": ["Python", "Machine Learning"]}'data = json.loads(json_data)print(data["skills"][0]) "Python" "Machine Learning" null エラーが発生する None 6. Pythonの公式ドキュメントや多数のライブラリが提供されているリポジトリはどこですか? GitLab SourceForge GitHub Stack Overflow None 7. 次のコードの実行結果を選んでください。 import jsondata = {"name": "Frank", "age": 28, "is_student": False}json_string = json.dumps(data, sort_keys=True)print(json_string) {"age": 28, "is_student": false, "name": "Frank"} {"name": "Frank", "age": 28, "is_student": false} {"is_student": false, "age": 28, "name": "Frank"} エラーが発生する None 8. 次のコードを実行したときの出力結果は何でしょうか? def multiply(a, b=5):return a * bprint(multiply(3))print(multiply(3, 2)) 3 6 15 6 15 10 6 15 None 9. 次のコードの出力は何ですか? x = 5y = 10result = x * y - x + yprint(result) 50 55 60 45 None 10. 次のコードを実行したときの出力結果は何でしょうか? def power(base, exponent=2):return base ** exponentprint(power(3))print(power(2, 3)) 6 8 9 8 6 16 9 8 None 11. 「Pythonのバージョン情報」を確認したいとき、対話モードで入力すべきコードはどれですか? get_version() version() python_version() import sys; sys.version None 12. 次のコードを実行したときの出力結果は何でしょうか? def power(base, exponent=2):return base ** exponentprint(power(3))print(power(2, 3)) 6 8 3 4 9 8 8 9 None 13. 次のコードを対話モードで実行した場合の出力は何ですか? x = "Python"x * 3 PythonPythonPython Python3 エラーが発生する PythonPython3 None 14. 次のコードで、ファイルからJSONデータを読み込むために使用する正しい関数を選んでください。 import jsonwith open("data.json", "r") as f:data = ??? json.loads(f) json.dumps(f) json.load(f) json.dump(f) None 15. 次のコードの実行結果として正しいものを選んでください。 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 16. 次のコードを対話モードで実行した場合の出力は何ですか? 10 / 3 3 3.3333 3.0 4 None 17. 次のコードの実行結果として正しいものを選んでください。 try:result = 10 / 2except ZeroDivisionError:print("Cannot divide by zero")else:print("Result:", result) "Cannot divide by zero" 何も出力されない "Result: 5.0" エラーが発生する None 18. Pythonにおける「PEP 8」は何を示していますか? データの暗号化方法 エラーハンドリング方法 パフォーマンス向上のための設定 コードのスタイルガイドライン None 19. Pythonの標準ライブラリを使用して、JSONデータを読み書きするためにインポートする必要があるモジュールを選んでください。 json pickle csv yaml None 20. 次のコードを実行したときの出力結果は何でしょうか? def identity(value=100):return valueprint(identity())print(identity(50)) 50 100 0 100 100 100 100 50 None 21. 次のコードで、関数subtractが呼び出されたときに引数が指定されなければxとyにそれぞれ0が入るように設定する方法はどれでしょうか? def subtract(x=0, y=0): return x - y def subtract(x, y=0): return x - y def subtract(x, y): x = 0 y = 0 return x - y def subtract(x=0, y): return x - y None 22. 次のコードの実行結果を選んでください。 try:with open("nonexistent.txt", "r") as f:content = f.read()except FileNotFoundError as e:print("Error:", e) "FileNotFoundError" エラーが発生する "Error: [Errno 2] No such file or directory: 'nonexistent.txt'" 何も出力されない None 23. 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 24. Pythonの「ガベージコレクション」はどのような目的で利用されているでしょうか? エラーの早期発見 メモリの自動解放 コードの高速実行 インタプリタの更新 None 25. 次のコードの実行結果を選んでください。 try:result = "text" + 5except TypeError as e:print("TypeError occurred:", e) "TypeError occurred" "TypeError occurred: can only concatenate str (not "int") to str" エラーが発生する 何も出力されない None 26. 次のコードを実行したときの出力結果は何でしょうか? def join_strings(str1, str2=", ", str3="!"):return str1 + str2 + str3print(join_strings("Hello"))print(join_strings("Hello", " and "))print(join_strings("Hello", " and ", "?")) Hello, ! Hello and ! Hello and ? Hello, Hello and Hello and ? Hello, ! Hello, ! Hello, ? Hello! Hello and Hello and ? None 27. 次のコードで、引数nameを省略すると「Guest」として扱う関数welcomeを正しく定義する方法はどれでしょうか? def welcome(name="Guest"): print("Welcome, " + name + "!") def welcome(name="Guest"): print("Hello, Guest!") def welcome(name="Guest"): return "Welcome, " + name + "!" def welcome(name): print("Welcome, Guest!") None 28. Pythonの「動的型付け」はどのような特徴を持っていますか? 変数の型はコンパイル時に決まる 変数の型は実行時に決まる 変数の型は固定され変更できない 変数の型は手動で設定する必要がある None 29. 次のコードの実行結果を選んでください。 import jsondata = {"name": "Bob", "age": 30, "city": "Tokyo"}json_data = json.dumps(data)print(type(json_data)) None 30. 次のコードの実行結果を選んでください。 import jsondata = {"name": "Eve", "age": None, "is_active": True}json_string = json.dumps(data)print(json_string) {"name": "Eve", "age": 0, "is_active": 1} エラーが発生する {"name": "Eve", "age": null, "is_active": true} {"name": "Eve", "age": None, "is_active": True} None 31. 次のコードの出力は何ですか? a = "Hello"b = a.replace("H", "J")print(a)print(b) Hello Hello Jello Hello Jello Jello Hello Jello None 32. 次のコードの実行結果を選んでください。 import jsondata = '{"name": "Charlie", "age": 35, "city": "Kyoto"}'parsed_data = json.loads(data)print(parsed_data["city"]) "Charlie" "Kyoto" 35 エラーが発生する None 33. 次のコードの実行結果を選んでください。 import jsonjson_data = '{"id": 101, "name": "Alice", "is_active": true}'data = json.loads(json_data)print(data["id"]) "Alice" true 101 エラーが発生する None 34. 次のコードで発生する例外の種類として正しいものを選んでください。 x = int("hello") ValueError TypeError NameError SyntaxError None 35. Pythonの対話モードで使用できる「ヘルプ」機能を起動するにはどうすればよいですか? start_help help_start() begin_help() help() None 36. 関数greetに名前を渡し、「Hello, 名前!」と出力する関数を正しく定義する方法はどれでしょうか? def greet(name): return "Hello, " + name + "!" def greet(name): print("Hello, name!") def greet(name): print("Hello, " + name + "!") greet(name): print("Hello, " + name + "!") None 37. 次のコードの出力は何ですか? def func(x):x += 5return xa = 10func(a)print(a) 10 15 エラーが発生する None None 38. Pythonにおける「識別子のルール」として誤っているものはどれですか? 数字で始めることができる アンダースコアで始めることができる 英字で始めることができる 大文字と小文字が区別される None 39. 次のコードの実行結果を選んでください。 try:result = "5" + 5except TypeError as e:print("Error type:", type(e)) "Error type: TypeError" "Error type: " "Error type: int" エラーが発生する None 40. 次のコードで、2つの数値を引数に取り、その合計を返す関数addを正しく定義する方法はどれでしょうか? def add(x y): return x + y def add(x, y): print(x + y) add(x, y): return x + y def add(x, y): return x + y None Time's up