Python 3エンジニア認定基礎試験~模擬試験⑦~ 2024年12月10日2024年12月10日 ailearn 1. 次のコードを実行したときの出力結果は何でしょうか? num = 12if num % 3 == 0:print("3の倍数")elif num % 4 == 0:print("4の倍数")else:print("3でも4でもない") 3の倍数 4の倍数 3でも4でもない 出力されない None 2. 変数xが正の数であるか、または偶数である場合に「条件を満たします」と表示するコードはどれでしょうか? if x > 0 and x % 2 == 0: print("条件を満たします") if x < 0 or x % 2 == 0: print("条件を満たします") if x > 0 or x % 2 == 0: print("条件を満たします") if x > 0 and x % 2 != 0: print("条件を満たします") None 3. 次のコードの出力結果は何ですか? stack = [2]for i in range(1, 4):stack.append(stack[-1] * i)stack.pop()print(stack) [2, 2, 4, 12] [2, 2, 4] [2, 2, 4, 6] [2, 4, 12] None 4. 次のコードの出力結果は何でしょうか? queue = []for i in range(1, 4):queue.append(i)for _ in range(2):queue.pop(0)print(queue) [1, 2, 3] [2, 3] [1] [3] None 5. キューqueueが空であるかどうかを判定するためのコードはどれでしょうか? queue.isEmpty() queue.size() == 0 queue == None len(queue) == 0 None 6. 次のうち、Pythonのstatisticsモジュールで最頻値(モード)を計算するための関数として正しいものを選んでください。 statistics.mean() statistics.median() statistics.mode() statistics.frequency() None 7. 次のコードを実行した場合の出力として正しいものを選んでください。 from datetime import datetime, timedeltacurrent = datetime(2024, 11, 17, 15, 0)adjusted = current - timedelta(hours=5, minutes=30)print(adjusted.strftime("%Y-%m-%d %H:%M")) 2024-11-17 10:30 2024-11-16 20:30 2024-11-17 09:30 2024-11-17 14:30 None 8. 次のコードの出力結果は何でしょうか? queue = [5, 15, 25]queue.append(queue.pop(0) * queue.pop(0))queue.append(queue.pop(0) - 10)print(queue) [5, 15] [75, 15] [75, 5] [5, 10] None 9. 次のコードを実行したときの出力結果は何でしょうか? x = 8if x % 2 == 0:if x % 4 == 0:print("4の倍数")else:print("2の倍数")else:print("その他") 4の倍数 2の倍数 その他 出力されない None 10. 次のコードでエラーが発生する原因を選んでください。 from math import piprint(math.pi) piが定義されていない mathモジュールがインポートされていない from math import piではmath.piとして使用できない インポート構文が間違っている None 11. 次のコードを実行した後、stackの内容は何でしょうか? stack = [1, 3, 5, 7]stack.append(stack.pop() * 2)stack.append(stack.pop() + 4) [1, 3, 5, 18] [1, 3, 5, 10] [1, 3, 7, 14] [1, 3, 5, 7, 14] None 12. 次のコードの出力結果は何ですか? queue = [10, 20, 30, 40]queue.pop(0)queue.append(queue.pop(0))queue.append(50)queue.pop(0)print(queue) [40, 20, 50] [30, 40, 50] [10, 30, 50] [20, 30, 40, 50] None 13. キューとして動作するリストqueueに対して、全ての要素を順番に取り出し、リストを空にするには次のどのコードが適切でしょうか? queue.pop(0) for _ in range(len(queue)): queue.pop(0) while queue: queue.pop(0) queue.clear() None 14. キューとして機能するリストqueueに要素10を追加するには、次のどのコードを使用すべきでしょうか? queue.append(10) queue.push(10) queue.insert(0, 10) queue.extend([10]) None 15. 次のコードを実行した後のstackの内容は何でしょうか? stack = [1, 2, 3]stack.append(4)stack.pop() [1, 2, 3] [1, 2, 3, 4] [1, 2] [4] None 16. スタックstackが空であるときにstack.pop()を実行するとどうなりますか? 空のリストが返される スタックの最初の要素が削除される IndexErrorが発生する Noneが返される None 17. 変数scoreが90以上の場合に「A」と表示し、80以上90未満の場合に「B」と表示するコードはどれでしょうか? if score = 80: print("B") if score > 90: print("A") elif score < 80: print("B") if score == 90: print("A") elif score < 80: print("B") if score >= 90: print("A") elif score >= 80: print("B") None 18. 変数numが偶数の場合に「偶数」と表示し、奇数の場合に「奇数」と表示するコードはどれでしょうか? if num // 2 == 1: print("偶数") else: print("奇数") if num % 2 != 0: print("偶数") else: print("奇数") if num % 2 == 0: print("偶数") else: print("奇数") if num % 2 == 1: print("偶数") else: print("奇数") None 19. datetimeモジュールで日時の差を計算するために使用されるクラスとして正しいものを選んでください。 datetime.datetime datetime.date datetime.time datetime.timedelta None 20. 次のコードの実行結果を選んでください。 from math import floor, ceilprint(floor(3.7), ceil(3.7)) 3 3 エラーになる 3 4 4 4 None 21. 次のコードでrandomモジュールのrandint関数を別名で使用した場合の正しいコードを選んでください。 from random import randint as ri import random.randint as ri include random.randint as ri from randint import random as ri None 22. 次のコードの実行結果を選んでください。 from os.path import existsprint(exists("test_file.txt")) TrueまたはFalse エラーが発生する 常にTrue 常にFalse None 23. 次のコードを実行した後のstackの内容は何でしょうか? stack = [1, 2, 3]for _ in range(2):stack.append(stack[-1] + stack[-2])stack.pop() [1, 2, 3, 4, 6] [1, 2, 3, 5, 8] [1, 2, 3, 8] [1, 2, 3, 5] None 24. 次のコードを実行した後のstackの内容は何でしょうか? stack = []for i in range(3):stack.append(i)stack.append(stack.pop() + stack.pop())stack.append(stack.pop() + stack.pop()) [1, 2, 3] [5] [] [3] None 25. 次のコードの実行結果を選んでください。 from math import piprint(pi) エラー None 3.14 3.141592653589793 None 26. 次のコードを実行したときの出力結果は何でしょうか? n = 15if n % 2 == 0:print("偶数")else:if n % 3 == 0:print("3の倍数")else:print("その他") 偶数 3の倍数 その他 出力されない None 27. スタックstackに要素がすでに追加されているとき、すべての要素を取り出して空にするにはどのようにすればよいでしょうか? stack.clear() stack.pop_all() for x in stack: stack.pop() stack.delete_all() None 28. 次のコードの実行結果を選んでください。 from random import randintprint(randint.__name__) randint random.randint エラーが発生する None None 29. 次のコードを実行した場合の出力として正しいものを選んでください。 import statisticsdata = [1, 2, 3, 4, 5, 6, 7, 8]variance = statistics.variance(data)print(round(variance, 2)) 6.0 4.0 7.0 5.0 None 30. 次のコードを実行した後のstackの内容は何でしょうか? stack = [100, 200, 300]stack.append(400)stack.pop()stack.pop()stack.append(500) [100, 200, 500] [100, 200, 300, 500] [100, 200] [300, 400, 500] None 31. 次のコードの出力結果を選んでください。 from math import sqrtprint(sqrt(16)) 4 16 エラー None None 32. 次のコードを実行した場合の出力として正しいものを選んでください。 import mathvalue = math.factorial(5)print(value) エラーが発生する 720 24 120 None 33. 次のコードの実行結果を選んでください。 import mathprint(math.__cached__) キャッシュされたファイルのパス None エラーが発生する math None 34. 次のコードを実行した後のqueueの内容は何でしょうか? queue = [1, 2, 3]queue.append(4)queue.pop(0) [1, 2, 3] [2, 3, 4] [1, 3, 4] [3, 4] None 35. 次のコードで、__cached__属性の内容として正しいものを選んでください。 import mathprint(math.__cached__) コンパイル済みのキャッシュファイルのパス モジュール名 None エラーが発生する None 36. 次のコードについて、現在の時刻を取得するために正しい関数を選んでください。 from datetime import datetimeprint(datetime.now().time()) datetime.date.now() datetime.now().time() datetime.current_time() datetime.time.now() None 37. 次のコードを実行した場合の出力として正しいものを選んでください。 from datetime import datetimedate = datetime(2024, 2, 29)days_to_add = 365new_date = date.replace(year=date.year + 1) + timedelta(days=days_to_add - 1)print(new_date.strftime("%Y-%m-%d")) 2025-02-28 2025-03-01 2025-02-29 エラーが発生する None 38. 変数tempが20以下なら「寒いです」と表示し、20より大きく30未満なら「快適です」と表示するコードはどれでしょうか? if temp <= 20: print("寒いです") elif temp < 30: print("快適です") if temp < 20: print("寒いです") elif temp <= 30: print("快適です") if temp < 30: print("快適です") elif temp <= 20: print("寒いです") if temp > 30: print("寒いです") elif temp < 20: print("快適です") None 39. 次のコードの出力結果は何でしょうか? queue = [5, 10, 15]for _ in range(2):queue.append(queue.pop(0) * 3)print(queue) [5, 10, 15, 15, 30] [15, 30, 15] [15, 15, 30] [10, 15, 15, 30] None 40. 変数yが負の数である場合に「負の数です」と表示するコードはどれでしょうか? if y > 0: print("負の数です") if y < 0: print("負の数です") if y == 0: print("負の数です") if y >= 0: print("負の数です") None Time's up