Python 3エンジニア認定基礎試験~模擬試験①~

1. 
次のコードを実行したときの出力結果は何でしょうか?

def dynamic_args(x, *args, y=10):
return x + sum(args) + y

print(dynamic_args(1, 2, 3))
print(dynamic_args(1, 2, 3, y=5))

2. 
Pythonの対話モードで終了するにはどのコマンドを使用しますか?

3. 
Python 3で導入された「f文字列(フォーマット文字列)」を使用した適切な記述方法はどれですか?

4. 
次のコードの実行結果を選んでください。

import json
data = {"name": "Frank", "hobbies": ["reading", "traveling", "coding"]}
with open("hobbies.json", "w") as f:
json.dump(data, f, indent=2)

5. 
次のコードを対話モードで実行した場合の出力は何ですか?

x = 2
y = x ** 3
y

6. 
次のコードの実行結果として正しいものを選んでください。

try:
open("nonexistent_file.txt", "r")
except FileNotFoundError:
print("File not found")
finally:
print("Execution complete")

7. 
Pythonの「論理演算子」として使用できないものはどれですか?

8. 
Pythonが「クロスプラットフォーム」に対応している意味として、正しいものはどれですか?

9. 
Pythonの「duck typing」の概念に基づく特徴として正しいものはどれですか?

10. 
Python 3において、print文の変更点として正しいものはどれですか?

11. 
次のコードの実行結果を選んでください。

try:
raise RuntimeError("Unexpected error")
except RuntimeError as e:
print("Caught runtime error:", e)

12. 
次のコードの実行結果を選んでください。

try:
result = "text" + 5
except TypeError as e:
print("TypeError occurred:", e)

13. 
次のコードの実行結果を選んでください。

import json
json_data = '{"A": 100, "B": 200, "C": 300}'
data = json.loads(json_data)
print(sum(data.values()))

14. 
Pythonが「オープンソース」であることの利点として、最も正しい説明はどれですか?

15. 
次のコードを実行したときの出力結果は何でしょうか?

def identity(value=100):
return value

print(identity())
print(identity(50))

16. 
Pythonの対話モードで「1から10までの整数を降順で表示する」には、どのようなコードを入力すべきですか?

17. 
デフォルト引数y=2を持つ関数multiplyを定義し、引数xをy倍にして返す方法はどれでしょうか?

18. 
Pythonにおける「識別子のルール」として誤っているものはどれですか?

19. 
次のコードの実行結果として正しいものを選んでください。

try:
result = 10 / 2
except ZeroDivisionError:
print("Cannot divide by zero")
else:
print("Result:", result)

20. 
次のコードを実行したときの出力結果は何でしょうか?

def concatenate(str1, str2=", ", str3="!"):
return str1 + str2 + str3

print(concatenate("Hello"))
print(concatenate("Hello", " World"))
print(concatenate("Hello", " World", "?"))

21. 
次のコードの実行結果を選んでください。

import json
data = '{"name": "Charlie", "age": 35, "city": "Kyoto"}'
parsed_data = json.loads(data)
print(parsed_data["city"])

22. 
次のコードを実行したときの出力結果は何でしょうか?

def add(a, b=2):
return a + b

result1 = add(5)
result2 = add(5, 3)

print(result1, result2)

23. 
次のコードの出力は何ですか?

x = 10
y = 3
result = x // y
print(result)

24. 
次のコードの実行結果を選んでください。

import json
data = {"name": "David", "age": 40, "city": "Hiroshima"}
json_string = json.dumps(data, indent=4)
print(json_string)

25. 
Pythonの対話モードで使用できる「ヘルプ」機能を起動するにはどうすればよいですか?

26. 
Pythonにおける「変数のスコープ」として、関数内で宣言された変数が関数の外で使用できない理由はどれですか?

27. 
次のコードで、JSON形式のデータをファイルに書き込むために使用する正しい関数を選んでください。

import json
data = {"name": "Bob", "age": 30, "city": "Osaka"}
with open("data.json", "w") as f:
???

28. 
次のコードの出力は何ですか?

a = [1, 2, 3]
print(a * 2)

29. 
次のコードを実行したときの出力結果は何でしょうか?

def greet_many(times=1):
return "Hello! " * times

print(greet_many())
print(greet_many(3))

30. 
「Pythonのバージョン情報」を確認したいとき、対話モードで入力すべきコードはどれですか?

31. 
次の出力を得るためには、対話モードでどのようなコードを入力すべきですか? コードをコピーする

Hello
World!

32. 
次のコードを実行したときの出力結果は何でしょうか?

def increment(number, step=1):
return number + step

print(increment(5))
print(increment(5, 2))

33. 
次のコードを実行したときの出力結果は何でしょうか?

def greet(name, message="Hello"):
return f"{message}, {name}!"

print(greet("Alice"))
print(greet("Bob", "Hi"))

34. 
次のコードの出力は何ですか?

a = [1, 2, 3]
print(a[-1])

35. 
リスト[10, 20, 30, 40, 50]の平均値を求めたいとき、どのコードを入力すべきですか?

36. 
Pythonの「ガベージコレクション」はどのような目的で利用されているでしょうか?

37. 
Pythonのバージョン3.x系で追加された、テキストのエンコーディングに関する標準規格は何ですか?

38. 
次のコードを実行したときの出力結果は何でしょうか?

def factorial(n):
if n == 0:
return 1
return n * factorial(n - 1)

print(factorial(3))
print(factorial(5))

39. 
次のコードを実行したときの出力結果は何でしょうか?

def add(x, y):
return x + y

def calculate_total(a, b, func=add):
return func(a, b)

print(calculate_total(5, 10))
print(calculate_total(5, 10, lambda x, y: x * y))

40. 
次のコードの実行結果を選んでください。

import json
json_data = '{"items": [10, 20, 30]}'
data = json.loads(json_data)
print(data["items"][1])

コメントを残すにはログインしてください。