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

1. 
Pythonのsplitlines()メソッドはどのような機能を持っていますか?

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

def outer_function():
x = 10

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

return inner_function()

print(outer_function())

3. 
文字列"Hello World"のスペースを削除して"HelloWorld"とするために使用するメソッドはどれですか?

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

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

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

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)

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

if True print("This will not work")

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

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

def my_function():
y = 7
print(y)

my_function()
print(y)

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

try:
raise ValueError("Invalid value")
except ValueError as e:
print("Caught exception:", e)

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

x = 5

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

outer_function()
print(x)

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

while True
print("Looping")

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

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

if True:
print("This is true")

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

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

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

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

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

x = 10

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

example_function()
print(x)

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

def my_function()
return "Hello"

18. 
Pythonで文字列を結合するために使用される演算子はどれですか?

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

def outer_function():
x = 5

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

return inner_function()

print(outer_function())

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

try:
raise ValueError("Invalid data provided")
except KeyError as e:
print("Caught KeyError:", e)
except ValueError as e:
print("Caught ValueError:", e)

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

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

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

x = 10

def outer_function():
x = 20

def inner_function():
return x + 5

return inner_function()

print(outer_function())
print(x)

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

while True print("Infinite loop")

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

def add(a, b)
return a + b

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

26. 
次のうち、文字列"Hello"を5回繰り返した文字列を生成するためのコードはどれですか?

27. 
変数animal = "cat"とsound = "meow"を使って、「The cat says meow」という文字列を生成するために入力すべきコードはどれですか?

28. 
次のリスト["one", "two", "three"]をスペース区切りで結合し、"one two three"という文字列を生成するコードはどれですか?

29. 
文字列text = "This is a test"から改行を挿入して「This is\na test」にするために必要なコードはどれですか?

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

text = "Line1\nLine2\nLine3"
result = text.split("\n")
print(result[1])

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

text = "Hello"
result = text + " " * 3 + "World"
print(result)

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

x = [1, 2, 3]

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

modify_list()
print(x)

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

z = [10, 20, 30]

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

modify_list()
print(z)

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

x = 10

def modify_variable():
x = 20
return x

print(modify_variable())
print(x)

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

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

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

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

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

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

items = ["apple", "banana", "cherry"]
output = " - ".join(items)
print(output)

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

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

example_function()

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

def outer_function():
x = 10

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

return inner_function()

print(outer_function())

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