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

1. 
グローバル変数を使用する際の注意点として適切なものはどれですか?

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

x = 10

def modify_variable():
x = 20
return x

print(modify_variable())
print(x)

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

print("Hello

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

def my_function()
return "Hello"

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

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

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

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

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

y = 100

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

outer_function()
print(y)

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

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

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

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

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

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

11. 
次のコードの出力結果は何でしょうか?

x = 0

def example_function():
global x
x = x + 2
return x

print(example_function())
print(x)

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

x = 10

def my_function():
global x
x += 5

my_function()
print(x)

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

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

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

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

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

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)

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

x = 10

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

print(modify_variable())

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

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

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

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

my_function()
print(y)

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

x = [1, 2, 3]

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

modify_list()
print(x)

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

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

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

x = 5

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

print(modify_variable())
print(x)

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

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

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

def extend_list(item, target=None):
if target is None:
target = []
target.append(item)
return target

list1 = extend_list(1)
list2 = extend_list(2, [])
list3 = extend_list(3)

print(list1)
print(list2)
print(list3)

25. 
次のコードでraise文の動作として正しい説明を選んでください。

if not isinstance(x, int):
raise TypeError("x must be an integer")

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

x = 5

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

print(multiply_by_two(x))
print(x)

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

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

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

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

print("Missing parenthesis in print statement"

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

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

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

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

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

34. 
次のコードの出力結果は何でしょうか?

x = 5

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

modify_variable()
print(x)

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

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

if x = 10:
print("x is 10")

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

print "Hello, World!"

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

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

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

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

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

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

print(my_function())

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