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

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

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

try:
lst = [1, 2, 3]
print(lst[5])
except IndexError:
print("Index out of range")

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

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

a = 10
b = 20
a, b = b, a
a

5. 
Pythonで「変数の宣言」において、以下の記述のうち正しいものはどれですか?

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

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

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

7. 
Pythonの「対話モード」を起動するためのコマンドはどれですか?

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

x = "Python"
x * 3

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

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

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

try:
result = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero")

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

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())

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

import json
data = {"name": "Frank", "age": 28, "is_student": False}
json_string = json.dumps(data, sort_keys=True)
print(json_string)

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

def identity(value=100):
return value

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

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

10 / 3

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

16. 
Pythonでの「複数行にまたがる文字列」を定義するために使用する方法はどれですか?

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

import json
json_data = '{"id": 101, "name": "Alice", "is_active": true}'
data = json.loads(json_data)
print(data["id"])

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

def add_items(item, items=None):
if items is None:
items = []
items.append(item)
return items

print(add_items("apple"))
print(add_items("banana"))

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

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

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

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

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

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

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

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

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

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

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

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

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

25. 
次のコードで、関数subtractが呼び出されたときに引数が指定されなければxとyにそれぞれ0が入るように設定する方法はどれでしょうか?

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

Hello
World!

27. 
Pythonにおける「PEP 8」は何を示していますか?

28. 
次のコードで発生する例外の種類として正しいものを選んでください。

x = int("hello")

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

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

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

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

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

print(default_and_keyword(1, z=5))

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

try:
with open("nonexistent.txt", "r") as f:
content = f.read()
except FileNotFoundError as e:
print("Error:", e)

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

try:
x = int("42")
y = int("hello")
print(x + y)
except ValueError as e:
print("Error:", e)

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

def modify_list(lst):
lst[0] = 100

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

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

x = [1, 2, 3]
y = x.copy()
y.append(4)
print(x)
print(y)

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

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

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

print(result1, result2)

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

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

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

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

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

5 + 5

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