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

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

def reset_list(values):
values = [0, 0, 0]

numbers = [1, 2, 3]
reset_list(numbers)
print(numbers)

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

def validate_input(value):
if not isinstance(value, int):
raise TypeError("Value must be an integer")
return value * 2

try:
print(validate_input("text"))
except TypeError as e:
print("Error:", e)

3. 
ローカル変数に関する正しい説明はどれですか?

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

x = [1, 2, 3]

def modify_list():
global x
x.append(4)

modify_list()
print(x)

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

print("Missing parenthesis in print statement"

6. 
次のコードの出力結果を求めてください。

words = ["data", "science", "python"]
sentence = " ".join(words)
print(sentence)

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

x = 5

def outer_function():
x = 10

def inner_function():
return x

return inner_function()

print(outer_function())

8. 
文字列「Hello\nWorld」を一行にまとめて「Hello World」にするために適切な方法はどれですか?

9. 
次のリスト["apple", "banana", "cherry"]の各要素を改行で区切って表示するために、適切なコードはどれですか?

10. 
次のコードの出力結果を求めてください。

text = "Line1\nLine2\nLine3"
print(text.replace("\n", " | "))

11. 
次のコードのnonlocalキーワードの用途として正しいものはどれですか?

def outer_function():
x = 10

def inner_function():
nonlocal x
x += 5

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

while True print("Infinite loop")

13. 
変数greeting = "Hello"とname = "Alice"を使って、「Hello, Alice!」と出力するためのコードはどれですか?

14. 
ローカル変数とグローバル変数のスコープを区別するために使用されるキーワードはどれですか?

15. 
次のうち、Pythonの文字列で改行を保持したまま文字列を定義する方法として正しいものはどれですか?

16. 
文字列フォーマットのf-string(フォーマット文字列)の記述方法として正しいものはどれですか?

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

x = [1, 2, 3

18. 
次のコードで出力を1行にまとめるために使用する引数はどれですか?

print("Hello")
print("World")

19. 
次のコードに関する正しい説明はどれですか?

x = 10

def example_function():
x = 5
print(x)

example_function()
print(x)

20. 
次のコードで「Hello」と「World」を改行で区切らずに出力するために必要な引数はどれですか?

print("Hello")
print("World")

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

y = 100

def modify_variable():
global y
y = "Changed"

modify_variable()
print(y)

22. 
イミュータブルなオブジェクトに該当するものはどれですか?

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

x = 10

def modify_variable():
x = 20
return x

print(modify_variable())
print(x)

24. 
ローカル変数に関する正しい説明はどれですか?

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

if True print("This will not work")

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

def my_function():
x = 5
x += 10
return x

print(my_function())

27. 
次のコードの問題点として正しいものを選んでください。

while True
print("Looping")

28. 
Pythonで複数行にわたる文字列を作成するために使う方法として正しいものはどれですか?

29. 
次のコードの出力結果を求めてください。

text = "Welcome"
repeat_text = text * 3
print(repeat_text)

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

if 5 > 3
print("5 is greater than 3")

31. 
次のコードの出力として正しいものを選んでください。

try:
raise Exception("Generic error")
except Exception as e:
print(type(e).__name__, ":", e)

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

def add(a, b)
return a + b

33. 
次のコードの結果を選択してください。

x = [1, 2, 3]

def modify_list(lst):
lst.append(4)

modify_list(x)
print(x)

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

for i in range(3):
print(i)

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

def outer_function():
x = 10

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

return inner_function()

print(outer_function())

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

z = [10, 20, 30]

def modify_list():
global z
z[1] = 99

modify_list()
print(z)

37. 
文字列text = "Line1\nLine2\nLine3"に含まれる改行ごとに分割し、リストにする方法はどれですか?

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

x = 5

def modify_variable():
global x
x = x * 2
return x

print(modify_variable())
print(x)

39. 
Pythonの文字列で改行を削除するための適切なメソッドはどれですか?

40. 
次のコードのエラー原因として正しいものを選んでください。

def calculate():
total = total + 1
print(total)

calculate()

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