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

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

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

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

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

x = 10

def modify_variable():
global x
x = "Hello"

modify_variable()
print(x)

4. 
変数name = "Alice"とage = 25の内容を使って「Alice is 25 years old」という文字列を生成するために入力すべきコードはどれですか?

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

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

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

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

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

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

while True print("Infinite loop")

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

def outer_function():
x = 10

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

return inner_function()

print(outer_function())

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

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

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

x = [1, 2, 3]

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

modify_list(x)
print(x)

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

14. 
文字列フォーマットのf-string(フォーマット文字列)の記述方法として正しいものはどれですか?

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

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

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

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

print(test_function())
print(y)

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

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

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

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

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

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

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

x = 1

def first_function():
global x
x += 1

def second_function():
global x
x *= 3

first_function()
second_function()
print(x)

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

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

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

try:
raise KeyError("Key not found")
except KeyError as e:
print("Caught KeyError:", e)
raise

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

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

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

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

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

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

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

28. 
次のコードのエラー原因として正しいものを選んでください。

def calculate():
total = total + 1
print(total)

calculate()

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

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

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

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

x = 10

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

print(modify_variable())
print(x)

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

z = [10, 20, 30]

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

modify_list()
print(z)

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

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

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

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

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

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

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

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

x = 10

def modify_variable():
x = 20
return x

print(modify_variable())
print(x)

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

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

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

def my_function()
return "Hello"

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

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

39. 
変数first = "Hello"とsecond = "World"を使って、「Hello, World!」という文字列を生成するために適切なコードはどれですか?

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

x = 3

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

print(modify_variable())
print(x)

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