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

1. 
Pythonの対話モードで、直前に実行したコードを再度実行するにはどうすればよいですか?

2. 
Pythonの対話モードで「10を3で割った余り」を表示したいとき、どのようなコードを入力すべきですか?

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

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

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

5. 
Pythonのインタプリタには「対話型シェル」が含まれています。このシェルの主な目的として正しいものはどれですか?

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

10 / 3

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

def greet(name="Guest"):
return "Hello, " + name + "!"

print(greet("Alice"))
print(greet())

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

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

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

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

def add_numbers(x, y=10, z=5):
return x + y + z

print(add_numbers(3))
print(add_numbers(3, 2))
print(add_numbers(3, 2, 1))

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

def func(x):
x += 5
return x

a = 10
func(a)
print(a)

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

def keyword_only_arg(*, x):
return x * 2

print(keyword_only_arg(x=5))

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

x = 2
y = x ** 3
y

14. 
次のコードの中で、「Hello, World!」と出力する関数greetを正しく定義する方法はどれでしょうか?

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

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

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

16. 
Pythonの対話モードで「'Hello, World!'」という文字列を画面に表示するには、どのコードを入力すべきですか?

17. 
関数greetに名前を渡し、「Hello, 名前!」と出力する関数を正しく定義する方法はどれでしょうか?

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

import json
data = {"name": "Eve", "age": 27, "skills": ["coding", "testing"]}
with open("profile.json", "w") as f:
json.dump(data, f)
with open("profile.json", "r") as f:
print(f.read())

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

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

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

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

x = 5
y = 10
result = x * y - x + y
print(result)

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

try:
result = "5" + 5
except TypeError as e:
print("Error type:", type(e))

22. 
Pythonの「動的型付け」はどのような特徴を持っていますか?

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

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

def calculate_discount(price, discount=0.1):
return price - (price * discount)

print(calculate_discount(100))
print(calculate_discount(200, 0.2))

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

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

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

try:
x = int("10.5")
except ValueError:
print("Conversion failed")

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

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

29. 
Pythonが「インタプリタ型言語」として提供される利点として適切なものはどれですか?

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

import json
data = {"status": None, "valid": True}
json_string = json.dumps(data)
print(json_string)

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

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

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

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

def default_and_keyword(x, y=10, *, z):
return x + y + z

print(default_and_keyword(1, z=5))

34. 
次のコードで、2つの数値を引数に取り、その合計を返す関数addを正しく定義する方法はどれでしょうか?

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

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"])

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

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

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

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

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

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

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

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

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

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