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

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

def modify_string(text):
text += " World"
return text

original_text = "Hello"
result = modify_string(original_text)
print(result)
print(original_text)

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

x = 5

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

print(modify_variable())
print(x)

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

x = 5

def outer_function():
global x
x = x * 2

outer_function()
print(x)

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

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

print(my_function())

5. 
次のコードの出力結果は何ですか?

x = 10

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

my_function()
print(x)

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

x = 3

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

print(modify_variable())
print(x)

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

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

names = ["John", "Paul", "George", "Ringo"]
result = ", ".join(names)
print(result)

9. 
文字列の中に改行を含めるにはどの方法を使うべきですか?

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

x = 10

def example_function():
print(x)

example_function()

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

try:
raise TypeError("Custom type error")
except KeyError as e:
print("Caught KeyError:", e)
except Exception as e:
print("Caught Exception:", e)

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

def append_item(value, items=None):
if items is None:
items = []
items.append(value)
return items

print(append_item(1))
print(append_item(2))

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

try:
raise ValueError("Test error")
except Exception as e:
print("Caught an exception")
raise e

14. 
raise文の役割として正しいものを選んでください。

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

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

y = 100

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

modify_variable()
print(y)

17. 
文字列の結合にjoin()メソッドを使用する場合、リスト["apple", "banana", "cherry"]をカンマ区切りの文字列にする正しいコードはどれですか?

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

try:
raise IndexError("Index out of range")
except KeyError as e:
print("Caught KeyError:", e)
except Exception as e:
print("Caught Exception:", e)

19. 
Pythonの文字列で改行を表すエスケープシーケンスはどれですか?

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

print("Missing parenthesis in print statement"

21. 
"Python3"という文字列から「3」を削除して"Python"にするコードはどれですか?

22. 
ミュータブル(変更可能)なオブジェクトに該当するものはどれですか?

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

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

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

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

def test_function():
y = 5
y += 1
return y

print(test_function())
print(y)

25. 
ローカル変数が削除されるタイミングとして正しいものはどれですか?

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

x = 10

def test_function():
x = 20
def modify_variable():
global x
x += 10
modify_variable()
print(x)

test_function()
print(x)

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

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

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

x = 10

def modify_variable():
x = 20
return x

print(modify_variable())
print(x)

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

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

text = """Line1
Line2
Line3"""
print(text.splitlines()[0])

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

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

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

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

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

x = 0

def increment():
global x
x += 1
return x

print(increment())
print(increment())

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

def modify_string(s):
s += " World"
return s

my_string = "Hello"
result = modify_string(my_string)
print(result)
print(my_string)

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

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

x = [1, 2, 3

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

def reset_counter():
count = 0

def increment():
nonlocal count
count += 1
return count

def reset():
nonlocal count
count = 0

return increment, reset

increment, reset = reset_counter()
print(increment())
print(increment())
reset()
print(increment())

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

x = 10

def modify_variable():
global x
x = x + 5
return x

print(modify_variable())
print(x)

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

x = 10

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

example_function()
print(x)

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

try:
raise RuntimeError("Runtime issue")
except RuntimeError as e:
print("Caught:", e)
raise

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