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

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

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

while True
print("Looping")

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

x = 5

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

outer_function()
print(x)

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

text = "Python"
result = text + " " + text[::-1]
print(result)

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

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

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

x = 10

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

print(modify_variable())
print(x)

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

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

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)

9. 
次のうち、Pythonの文字列において改行を削除する方法として正しいものはどれですか?

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

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

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

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

print "Hello, World!"

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

def outer_function():
x = 5

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

return inner_function()

print(outer_function())

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

for i in range(5)
print(i)

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

def my_function()
return "Hello"

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

try:
raise ValueError("This is a value error")
except ValueError as e:
print("Caught error:", e)

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

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

def check_divisor(y):
if y == 0:
raise ZeroDivisionError("Divisor cannot be zero")
return 10 / y

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

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

x = 5

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

print(modify_variable())
print(x)

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

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

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

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

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

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

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

x = 10

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

print(modify_variable())

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

x = 10

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

example_function()
print(x)

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

27. 
次のコードを実行した場合の出力結果を選んでください。

def set_variable():
y = 20
return y

set_variable()
print(y)

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

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

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

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

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

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

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

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

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

x = 10
if x > 5
print("x is greater than 5")

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

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

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

my_function()
print(y)

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

x = 10

def modify_variable():
x = 20
return x

print(modify_variable())
print(x)

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

37. 
次のコードで発生する例外の種類として正しいものを選んでください。

raise KeyError("Key not found")

38. 
次のコードの出力を1行にするために使うべき引数はどれですか?

print("Hello")
print("Python")

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

def check_value(x):
if x < 0:
raise ValueError("Negative value not allowed")
return x * 2

try:
print(check_value(-5))
except ValueError as e:
print("Error:", e)

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

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

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