Python 3エンジニア認定基礎試験~模擬試験⑦~ 2024年12月10日2024年12月10日 ailearn 1. 次のコードの実行結果を選んでください。 import mathprint(math.pow(2, 3)) 2 エラー 8.0 None None 2. 次のコードの出力結果は何でしょうか? queue = [10, 20, 30]queue.append(queue.pop(0) + queue[-1])queue.append(queue.pop(0) * 2)print(queue) [30, 40, 40] [30, 60, 40] [30, 40, 60] [20, 30, 40, 50] None 3. 次のコードの出力結果は何でしょうか? 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 4. datetimeモジュールで日時の差を計算するために使用されるクラスとして正しいものを選んでください。 datetime.datetime datetime.date datetime.time datetime.timedelta None 5. 次のコードを実行したときの出力結果は何でしょうか? score = 75if score >= 90:print("A")elif score >= 80:print("B")elif score >= 70:print("C")else:print("D") A B C D None 6. 次のコードの実行結果を選んでください。 from random import randintprint(randint.__name__) randint random.randint エラーが発生する None None 7. Pythonのモジュールに関する次の記述のうち、__name__属性の役割として正しいものを選んでください。 モジュールの名前を格納する。 モジュールのファイルパスを格納する。 現在の関数名を格納する。 実行時にモジュールが直接実行されたか、インポートされたかを判別する。 None 8. 次のコードを実行した場合の出力として正しいものを選んでください。 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 9. 次のコードを実行したときの出力結果は何でしょうか? x = -10if x > 0:print("正の数")elif x < 0:print("負の数")else:print("ゼロ") 正の数 出力されない ゼロ 負の数 None 10. 次のコードの実行結果を選んでください。 import timestart = time.time()time.sleep(2)end = time.time()print(end - start) 約2.0秒 約1.0秒 約0.0秒 エラーになる None 11. 次のコードを実行した後、queueの内容は何でしょうか? queue = [1, 2, 3]queue.pop(0)queue.append(4)queue.pop(0)queue.append(5)queue.pop(0) [4, 5] [3, 4, 5] [5] [1, 5] None 12. 次の記述のうち、Pythonのimportに関して正しいものを選んでください。 モジュールをインポートするときは、常にimport module_nameを使用する必要がある。 importされたモジュールは、スクリプト終了後も永続的にメモリに保持される。 importは同じスクリプト内で複数回記述することができるが、2回目以降の実行は無視される。 モジュール内の関数をインポートするにはincludeを使用する。 None 13. Pythonのstatisticsモジュールで、平均値を計算するための関数として正しいものを選んでください。 statistics.mean() statistics.median() statistics.mode() statistics.average() None 14. キューとして機能するリストqueueに要素10を追加するには、次のどのコードを使用すべきでしょうか? queue.append(10) queue.push(10) queue.insert(0, 10) queue.extend([10]) None 15. 次のコードの出力結果は何ですか? 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 16. 次のコードの実行結果を選んでください。 import sysprint(sys.__file__) None sysモジュールのファイルパス エラーが発生する sys None 17. 次のコードを実行したときの出力結果は何でしょうか? x = 7y = 4if x > 5:if y < 5:print("x > 5 かつ y < 5")else:print("x > 5 かつ y >= 5")else:print("x <= 5") x > 5 かつ y >= 5 x <= 5 x > 5 かつ y < 5 出力されない None 18. 次のコードを実行した場合の出力として正しいものを選んでください。 import statisticsdata = [10, 20, 30, 40, 50]mean = statistics.mean(data)stdev = statistics.stdev(data)print(round(mean + stdev, 2)) 50.81 45.81 60.81 70.81 None 19. Pythonにおいて、標準ライブラリモジュールmathを使用するための適切なコードを選んでください。 import math import Math from math import * include math None 20. 次のコードの実行結果を選んでください。 import randomprint(random.__name__) __main__ None エラーが発生する random None 21. 次のコードの実行結果を選んでください。 import mathprint(math.__cached__) キャッシュされたファイルのパス None エラーが発生する math None 22. 次のコードを実行した場合の出力として正しいものを選んでください。 import mathresult = math.log10(100) + math.factorial(3)print(result) 8.0 9.0 6.0 エラーが発生する None 23. 次のコードの出力結果は何でしょうか? queue = []for i in range(3):queue.append(i * 2)queue.pop(0)queue.append(queue.pop(0) + 5)print(queue) [1, 2, 5] [4, 10] [2, 5, 7] [4, 7] None 24. 次のコードを実行した場合の出力として正しいものを選んでください。 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 25. 変数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 26. 次のコードの出力結果は何でしょうか? 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 27. 次のコードの実行結果を選んでください。 import mathprint(hasattr(math, "__file__")) True False エラーが発生する None None 28. キューqueueが空であるかどうかを判定するためのコードはどれでしょうか? queue.isEmpty() queue.size() == 0 queue == None len(queue) == 0 None 29. 変数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 30. 次のコードの出力結果は何でしょうか? queue = []for i in range(3):queue.append(i + 1)queue.append(queue.pop(0) + 5)print(queue) [5, 6, 7] [1, 3, 5] [6, 7] [11, 3, 7] None 31. 次のコードを実行したときの出力結果は何でしょうか? temperature = 22if temperature > 30:print("暑いです")elif temperature >= 20:print("快適です")else:print("寒いです") 暑いです 快適です 寒いです 出力されない None 32. 次のコードでtimeモジュールを別名でインポートした場合、関数sleepにアクセスする正しい方法を選んでください。 import time as tm time.sleep(1) t.sleep(1) sleep(1) tm.sleep(1) None 33. 次のコードを実行したときの出力結果は何でしょうか? a = 3b = 8if a 10:print("条件1が成立")elif a 5:print("条件2が成立")else:print("どちらも成立しません") 条件1が成立 条件2が成立 どちらも成立しません 出力されない None 34. 次のコードを実行したときの出力結果は何でしょうか? x = 7if x > 5:if x < 10:print("5より大きく10未満です")else:print("10以上です")else:print("5以下です") 5より大きく10未満です 10以上です 5以下です 出力されない None 35. 次のコードの実行結果を選んでください。 import osprint(os.__package__) os None モジュールのパッケージ名 エラーが発生する None 36. 次のコードを実行した後の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 37. 変数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 38. 次のコードを実行した場合の出力として正しいものを選んでください。 from datetime import datetime, timedeltanow = datetime(2024, 11, 17)next_week = now + timedelta(weeks=1)print(next_week.strftime("%A")) Monday Saturday Tuesday Sunday None 39. 次のコードの実行結果を選んでください。 import osprint(hasattr(os, "__doc__")) False True None エラーが発生する None 40. 次のコードを実行した場合の出力として正しいものを選んでください。 from datetime import datetimecurrent = datetime(2024, 11, 17, 12, 30)print(current.strftime("%I:%M %p")) 12:30 AM 12:30 エラーが発生する 12:30 PM None Time's up