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

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

def multiply(a, b=2):
return a * b

print(multiply(5, b=3))

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

class MyClass:
def __init__(self, value):
self.value = value

obj = MyClass(10)
obj.value = 20
print(obj.value)

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

s = "abcdefghij"
print(s[2:9:3])

4. 
文字列s = "abcdefg"の逆順を取得するスライスはどれですか?

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

class MyClass:
def __init__(self, name):
self.name = name

obj = MyClass("Alice")
print(obj.name)

6. 
次のうち、Pythonで乱数を生成するのに使用されるライブラリはどれですか?

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

def repeat_string(s, times=3, separator=" "):
return separator.join([s] * times)

print(repeat_string("Hi", times=2))

8. 
次のコードのクラス定義として正しいものを選んでください。

class MyClass:
pass

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

def sum_numbers(a=1, b=2, c=3):
return a + b + c

print(sum_numbers(c=6))

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

class MyClass:
class_variable = 0

def increment(self):
MyClass.class_variable += 1

obj1 = MyClass()
obj2 = MyClass()

obj1.increment()
print(obj2.class_variable)

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

def calculate_area(length=5, width=3):
return length * width

print(calculate_area(width=4))

12. 
次のコードについて、obj.class_variable = "new value"の結果として正しい説明を選んでください。

class MyClass:
class_variable = "shared"

obj = MyClass()
obj.class_variable = "new value"
print(MyClass.class_variable)

13. 
abs(-3.7)の結果はどれですか?

14. 
0.2 + 0.1 == 0.3の評価結果はどれですか?

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

def introduce(name, age, city="Unknown"):
return f"{name} is {age} years old and lives in {city}."

print(introduce("Sam", 30))

16. 
キーワード引数に関する正しい説明はどれですか?

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

def greet(name, message="Welcome", punctuation="!"):
return f"{message}, {name}{punctuation}"

print(greet("Alice", punctuation="!!!"))

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

def repeat_string(s, times=3, separator=" "):
return separator.join([s] * times)

print(repeat_string("Hi", times=2))

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

def multiply(a, b=2):
return a * b

print(multiply(5))

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

class MyClass:
@staticmethod
def greet():
return "Hello from static method"

print(MyClass.greet())

21. 
文字列s = "abcdefg"の偶数番目の文字を取得するスライスはどれですか?

22. 
次のコードについて、finallyブロックが実行されるタイミングとして正しいものを選んでください。

try:
raise ValueError("An error occurred")
except ValueError:
print("Caught ValueError")
finally:
print("Executing cleanup")

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

def divide(a, b=1):
return a / b

print(divide(10, b=2))

24. 
次のコードについて、クラス変数へのアクセス方法として正しいものを選んでください。

class MyClass:
class_variable = "shared"

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

def greet(name, message="Hello"):
print(f"{message}, {name}!")

greet(name="Alice", message="Hi")

26. 
文字列s = "Python Programming"から文字「P」だけを取得するスライスはどれですか?

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

class MyClass:
def __init__(self, value):
self.value = value

def __eq__(self, other):
return self.value == other.value

obj1 = MyClass(10)
obj2 = MyClass(10)
print(obj1 == obj2)

28. 
Pythonで無限大を表すにはどのようにしますか?

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

def greet(name, message="Hello"):
return f"{message}, {name}!"

print(greet("Alice", "Hi"))

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

def build_profile(first_name, last_name, age=25, country="Japan"):
return f"{first_name} {last_name}, {age} years old, from {country}"

print(build_profile("Tom", "Smith", country="USA"))

31. 
次のコードにおいて、クラス変数として正しい記述を選んでください。

class MyClass:
???
def __init__(self, value):
self.value = value

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

try:
print("Start")
finally:
print("Cleanup complete")

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

class MyClass:
class_variable = [1, 2, 3]

obj = MyClass()
obj.class_variable = [4, 5, 6]

print(MyClass.class_variable)

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

class MyClass:
class_variable = "shared"

obj = MyClass()
obj.class_variable = "instance value"
print(MyClass.class_variable)

35. 
次のコードについて、正しい説明を選んでください。

class MyClass:
class_attribute = "shared value"

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

def show_info(name="John", age=25):
print(f"{name} is {age} years old.")

show_info(age=30)

37. 
3進数でint("102", 3)の結果は次のどれですか?

38. 
import mathの後にmath.ceil(4.3)を実行すると結果はどれですか?

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

class MyClass:
def __init__(self, name):
self.name = name

obj = MyClass("Bob")
obj.name = "Alice"
print(obj.name)

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

def describe_item(name, price=100, stock=10):
return f"Item: {name}, Price: {price}, Stock: {stock}"

print(describe_item("Notebook", stock=5))

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