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

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

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

def multiply(a, b=5):
return a * b

print(multiply(3))
print(multiply(3, 2))

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

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

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

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

def multiply_values(x, y=2, z=3):
return x * y * z

print(multiply_values(4))
print(multiply_values(4, 5))
print(multiply_values(4, 5, 6))

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

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

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

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

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

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

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

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

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

print(join_strings("Hello"))
print(join_strings("Hello", " and "))
print(join_strings("Hello", " and ", "?"))

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

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

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

print(divide(6))
print(divide(6, 2))

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

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

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

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

def calculate_area(width, height=2):
return width * height

print(calculate_area(4))
print(calculate_area(4, 3))

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

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

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

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

19. 
「10から20までの範囲で、2の倍数のみをリストで表示」するには、どのコードを入力すべきですか?

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

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

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

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

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

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

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

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

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

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

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

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

def greet_many(times, name="Guest"):
return (f"Hello, {name}!" * times).strip()

print(greet_many(2))
print(greet_many(3, "Alice"))

26. 
Pythonの「コメント」を記述する際に使用する記号はどれですか?

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

x = 2
y = x ** 3
y

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

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

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

29. 
Pythonでの「四則演算」の順序として最も正しいものはどれですか?

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

31. 
Pythonのコードブロックは何を使用して定義されますか?

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

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

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

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

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

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

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

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

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

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

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

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

def format_text(text, prefix="*", suffix="*"):
return prefix + text + suffix

print(format_text("Hello"))
print(format_text("Hello", prefix="~"))
print(format_text("Hello", suffix="?"))

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

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