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

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

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

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

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

def add(a, b)
return a + b

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

x = [1, 2, 3]

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

modify_list(x)
print(x)

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

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

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

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

y = 100

def outer_function():
y = 200
def inner_function():
global y
y += 50
inner_function()
print(y)

outer_function()
print(y)

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

x = 5

def outer_function():
x = 10

def inner_function():
return x

return inner_function()

print(outer_function())

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

y = 100

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

modify_variable()
print(y)

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

a = "Python"
b = "Programming"
result = a + " " + b
print(result)

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

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

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

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

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

def create_multiplier(factor):
def multiplier(x):
return x * factor
return multiplier

times_three = create_multiplier(3)
times_five = create_multiplier(5)

print(times_three(10))
print(times_five(10))

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

x = 10

def example_function():
print(x)

example_function()

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

text = "Line1\nLine2\nLine3"
lines = text.splitlines()
print(lines)

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

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

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

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

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

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

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

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

def outer_function():
x = 10

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

return inner_function()

print(outer_function())

20. 
次のコードを実行したときにエラーが発生する理由として正しいものを選んでください。

def example_function():
x += 1
print(x)

example_function()

21. 
次のうち、文字列の結合に使われないメソッドはどれですか?

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

x = 3

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

print(modify_variable())
print(x)

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

def check_divisible(a, b):
if b == 0:
raise ZeroDivisionError("Cannot divide by zero")
return a / b

try:
print(check_divisible(10, 0))
except ZeroDivisionError as e:
print("Error:", e)

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

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

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)

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

try:
raise TypeError("Invalid type")
except Exception as e:
print("Caught Exception:", e)

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

x = 10

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

my_function()
print(x)

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

x = 5

def multiply_by_two(x):
x = x * 2
return x

print(multiply_by_two(x))
print(x)

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

print("Missing parenthesis in print statement"

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

for i in range(5)
print(i)

31. 
グローバル変数を関数内で変更するために使用するキーワードは何ですか?

32. 
次のコードで正しい出力を選んでください。

try:
raise RuntimeError("Unexpected error occurred")
except RuntimeError as e:
print(e)

33. 
リスト["Python", "Java", "C++"]を結合して"Python and Java and C++"とするためのコードはどれですか?

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

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

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

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

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

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

x = 5

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

outer_function()
print(x)

37. 
改行を含む文字列"Hello\nWorld"をスペースで区切って一行にまとめるためのコードはどれですか?

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

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

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

def greet(name):
print("Hello,", name)

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

x = [1, 2, 3]

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

modify_list()
print(x)

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