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

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

def func(x, y=10):
return x + y

print(func(5))
print(func(5, 15))

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

def join_strings(*args):
return ", ".join(args)

print(join_strings("apple", "banana", "cherry"))
print(join_strings("Python", "Java"))

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

def add_three(a, b, c=1):
return a + b + c

print(add_three(2, 3))
print(add_three(2, 3, 4))

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

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

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

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

10 / 3

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

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

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

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

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

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

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

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

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

for i in range(1, 5):
if i == 3:
continue
print(i)

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

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

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

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

print(result1, result2)

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

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

14. 
Pythonの対話モードでエラーの詳細な情報を表示するには、何を入力しますか?

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

16. 
2つの文字列を結合して返す関数concatを正しく定義するコードはどれでしょうか?

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

a = "Hello"
b = a.replace("H", "J")
print(a)
print(b)

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

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

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

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

x = 2
y = x ** 3
y

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

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

21. 
Pythonのファイル拡張子として正しいものはどれですか?

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

def divide(a, b=1):
return a / b

result1 = divide(6)
result2 = divide(6, 2)

print(result1, result2)

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

def power(base, exponent=2):
return base ** exponent

print(power(3))
print(power(2, 3))

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

x = "Python"
x * 3

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

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

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

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

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

def power(base, exponent=2):
return base ** exponent

print(power(3))
print(power(2, 3))

28. 
Pythonの創始者である「グイド・ヴァンロッサム」が、Pythonの開発を始めたきっかけとなったのはどの言語の後継を意識したからですか?

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

import json
data = {"name": "Bob", "age": 30, "city": "Tokyo"}
json_data = json.dumps(data)
print(type(json_data))

30. 
Pythonの「標準ライブラリ」に含まれていないものはどれですか?

31. 
Pythonの公式ドキュメントや多数のライブラリが提供されているリポジトリはどこですか?

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

import json
data = {"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"])

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

try:
x = 10 / 0
except ZeroDivisionError:
print("Division by zero")
except Exception:
print("General exception")

34. 
Pythonの標準ライブラリを使用して、JSONデータを読み書きするためにインポートする必要があるモジュールを選んでください。

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

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

36. 
対話モードで次の行を続けて書く必要があるときに使用する記号はどれですか?

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

import json
json_data = '{"key": null}'
data = json.loads(json_data)
print(data["key"] is None)

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

try:
x = int("123")
except ValueError:
print("Invalid value")
else:
print("Conversion successful:", x)
finally:
print("End of program")

39. 
Pythonの主な特徴の1つとして、以下のうち正しい説明はどれですか?

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

import json
data = {"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])

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