一般社団法人 ITエンジニア育成検定協会
—
by
Python技術試験 公式模試問題集
1 / 134
下記のコードを実行した結果として正しいものを選択してください。 x = ‘7.5’ y = int(float(x)) print(y)
2 / 134
下記のコードを実行した結果として正しいものを選択してください。 number = 256 binary_str = bin(number) hex_str = hex(number)
print(‘Binary:’, binary_str, ‘Hexadecimal:’, hex_str)
3 / 134
下記のコードを実行した結果として正しいものを選択してください。 a = 7 b = 3 a *= b print(a)
4 / 134
下記のコードを実行した結果として正しいものを選択してください。 number = 7.25 print(int(number))
5 / 134
下記のコードを実行した結果として正しいものを選択してください。 x = 7 y = 2 print(‘The result of 7 // 2 is:’, x // y)
6 / 134
下記のコードを実行した結果として正しいものを選択してください。 number_str = ‘3.14’ number_float = float(number_str) number_int = int(number_float) print(number_int)
7 / 134
下記のコードを実行した結果として正しいものを選択してください。 a = 10 b = 20 c = ’30’ d = a + b + int(c) print(d)
8 / 134
下記のコードを実行した結果として正しいものを選択してください。 num_str = ‘7.25’ num_int = int(float(num_str)) print(num_int)
9 / 134
下記のコードを実行した結果として正しいものを選択してください。 def outer_function(): a = 20 def inner_function(): a = 30 print(‘a =’, a) inner_function() print(‘a =’, a)
a = 10 outer_function() print(‘a =’, a)
10 / 134
下記のコードを実行した結果として正しいものを選択してください。 x = 10 def increment(): global x x += 1 increment() print(x)
11 / 134
下記のコードを実行した結果として正しいものを選択してください。 x = 5 y = 3 print(f'{x} + {y} = {x + y}’)
12 / 134
下記のコードを実行した結果として正しいものを選択してください。 values = [0, ”, ‘Python’, [], {}, [1, 2, 3], {1: ‘one’}, None, False, True] results = [bool(value) for value in values] print(results)
13 / 134
下記のコードを実行した結果として正しいものを選択してください。 a = 5 b = 10 a = b b = a + b print(a, b)
14 / 134
下記のコードを実行した結果として正しいものを選択してください。 number1 = 10 number2 = 20 result = number1 * number2 print(result)
15 / 134
下記のコードを実行した結果として正しいものを選択してください。 values = [0, ”, [], {}, set(), ‘False’, False, 1, -1]
count_true = 0 for v in values: count_true += bool(v)
print(count_true)
16 / 134
下記のコードを実行した結果として正しいものを選択してください。 def outer_func(): a = 20 def inner_func(): a = 30 print(‘Inner a:’, a) inner_func() print(‘Outer a:’, a)
a = 10 outer_func() print(‘Global a:’, a)
17 / 134
下記のコードを実行した結果として正しいものを選択してください。 x = 5 y = 2 print(x ** y)
18 / 134
下記のコードを実行した結果として正しいものを選択してください。 a = 10 b = 5 c = ‘2’ d = a + b * int(c) print(d)
19 / 134
下記のコードを実行した結果として正しいものを選択してください。 a = 5 b = 10 c = b b = a a = c
print(‘a =’, a, ‘b =’, b)
20 / 134
下記のコードを実行した結果として正しいものを選択してください。 x = ‘100’ y = 200 z = float(x) + y print(z)
21 / 134
下記のコードを実行した結果として正しいものを選択してください。 a = 8 b = 3 c = a ** b
print(c)
22 / 134
23 / 134
下記のコードを実行した結果として正しいものを選択してください。 alphabet = ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’ my_slice = slice(5, 20, 3) result = alphabet[my_slice] print(result)
24 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] def is_odd(n): return n % 2 != 0
odd_numbers = list(filter(is_odd, numbers)) print(odd_numbers)
25 / 134
下記のコードを実行した結果として正しいものを選択してください。 my_list = [‘a’, ‘b’, ‘c’, ‘d’] reversed_list = list(reversed(my_list)) print(reversed_list)
26 / 134
下記のコードを実行した結果として正しいものを選択してください。 my_string = ‘Python Programming’ my_slice = slice(7, 18) result = my_string[my_slice] print(result)
27 / 134
下記のコードを実行した結果として正しいものを選択してください。 iterable = [‘apple’, ‘banana’, ‘cherry’] iterator = iter(iterable)
first_item = next(iterator) second_item = next(iterator) third_item = next(iterator) forth_item = next(iterator)
28 / 134
下記のコードを実行した結果として正しいものを選択してください。 from math import sqrt as s, factorial as f
result = f(5) / s(25) print(result)
29 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3] numbers.sort() print(numbers)
new_numbers = sorted(numbers, reverse=True) print(new_numbers)
30 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = iter([1, 2, 3]) output = [] while True: try: number = next(numbers) output.append(number) except StopIteration: break
print(output)
31 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [3, 1, 4, 1, 5, 9, 2, 6, 5] numbers.sort() print(numbers)
alphabets = [‘d’, ‘a’, ‘c’, ‘b’] result = sorted(alphabets) print(result)
32 / 134
下記のコードを実行した結果として正しいものを選択してください。 my_list = [‘apple’, ‘banana’, ‘cherry’] for item in reversed(my_list): print(item)
33 / 134
下記のコードを実行した結果として正しいものを選択してください。 data = [‘Python’, ‘Java’, ‘C++’, ‘JavaScript’] result = len(data[2])
print(result)
34 / 134
下記のコードを実行した結果として正しいものを選択してください。 def concat_strings(*args, sep=’/’): return sep.join(args)
result = concat_strings(‘apple’, ‘banana’, ‘cherry’, sep=’, ‘) print(result)
35 / 134
下記のコードを実行した結果として正しいものを選択してください。 number = 1024 formatted_string = ‘{:b}’.format(number) print(formatted_string)
36 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [1, 2, 3, 4, 5] def square(x): return x * x
result = map(square, numbers) print(list(result))
37 / 134
下記のコードを実行した結果として正しいものを選択してください。 values = [10, 20, 0, -10, 30]
result_all = all(value > 0 for value in values) result_any = any(value > 0 for value in values)
print(f’all: {result_all}, any: {result_any}’)
38 / 134
下記のコードを実行した結果として正しいものを選択してください。 names = [‘Alice’, ‘Bob’, ‘Charlie’] ages = [24, 30, 28] for name, age in zip(names, ages): print(f'{name} is {age} years old.’)
39 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5] numbers.sort() print(numbers)
40 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [3, 5, 1, 4, 2] max_value = max(numbers) min_value = min(numbers) result = max_value + min_value print(result)
41 / 134
下記のコードを実行した結果として正しいものを選択してください。 code = ‘result = [str(i) for i in range(5)]’ exec(code) print(eval(‘ “+”.join(result) ‘))
42 / 134
下記のコードを実行した結果として正しいものを選択してください。 def greet(name, message=’Hello’): return f'{message}, {name}!’
print(greet(‘Alice’)) print(greet(‘Bob’, ‘Good morning’)) print(greet(‘Charlie’, message=’How do you do’))
43 / 134
下記のコードを実行した結果として正しいものを選択してください。 name = input(‘あなたの名前を入力してください: ‘) print(‘こんにちは、’ + name + ‘さん!’)
44 / 134
下記のコードを実行した結果として正しいものを選択してください。 names = [‘Alice’, ‘Bob’, ‘Charlie’] ages = [24, 50, 18] for name, age in zip(names, ages): print(f'{name} is {age} years old.’)
45 / 134
下記のコードを実行した結果として正しいものを選択してください。 code = “def add(x, y): return x + y” exec(code) result = eval(‘add(2, 3)’) print(result)
46 / 134
下記のコードを実行した結果として正しいものを選択してください。 my_list = [‘apple’, ‘banana’, ‘cherry’, ‘date’]
result = len(my_list)
47 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [15, 8, 22, 5, 10] max_value = max(numbers) min_value = min(numbers) average = (max_value + min_value) / 2
print(‘最大値:’, max_value) print(‘最小値:’, min_value) print(‘平均値:’, average)
48 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = [‘apple’, ‘banana’, ‘cherry’] fruits.append(‘orange’) print(fruits)
49 / 134
下記のコードを実行した結果として正しいものを選択してください。 number = 123456.789 formatted_number = ‘{:,.2f}’.format(number) print(formatted_number)
50 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] def is_even(n): return n % 2 == 0
filtered_numbers = list(filter(is_even, numbers)) print(filtered_numbers)
51 / 134
下記のコードを実行した結果として正しいものを選択してください。 def greet(name, greeting=’Hello’): return f'{greeting}, {name}!’
print(greet(‘Alice’)) print(greet(‘Bob’, ‘Good morning’)) print(greet(‘Charlie’, greeting=’Greetings’))
52 / 134
53 / 134
下記のコードを実行した結果として正しいものを選択してください。 def print_args(*args): for i, arg in enumerate(args): print(f’Argument {i}: {arg}’)
print_args(‘Python’, ‘is’, ‘fun’, ‘!’)
54 / 134
下記のコードを実行した結果として正しいものを選択してください。 name = input(‘あなたの名前を教えてください: ‘) age = input(‘あなたの年齢を教えてください: ‘)
print(f’こんにちは、{name}さん!あなたは{age}歳ですね。’)
55 / 134
下記のコードを実行した結果として正しいものを選択してください。 values = [10, 20, 0, 30] print(all(value > 0 for value in values), any(value > 0 for value in values))
56 / 134
下記のコードを実行した結果として正しいものを選択してください。 import math import os as operating_system
value = math.pi path = operating_system.getcwd() print(f’The value of pi is {value} and the current working directory is {path}’)
57 / 134
下記のコードを実行した結果として正しいものを選択してください。 def multiply(a, b=2): return a * b
result1 = multiply(3) result2 = multiply(3, 5) print(‘result1:’, result1, ‘result2:’, result2)
58 / 134
下記のコードを実行した結果として正しいものを選択してください。 def compute_sum(end, start=1, step=1): total = 0 for i in range(start, end, step): total += i return total
result = compute_sum(10, step=2) print(result)
59 / 134
60 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3] numbers.sort() print(‘Sort:’, numbers) sorted_numbers = sorted(numbers, reverse=True) print(‘Sorted:’, sorted_numbers)
61 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = {‘apple’: 10, ‘banana’: 5, ‘cherry’: 15}
for fruit in fruits: fruits[fruit] += 5
print(fruits[‘banana’])
62 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = [‘apple’, ‘banana’, ‘cherry’, ‘date’] removed_item = fruits.pop(2) print(‘Removed:’, removed_item) print(‘Remaining fruits:’, fruits)
63 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = [‘apple’, ‘banana’, ‘cherry’, ‘date’] fruits.pop(1) fruits.insert(1, ‘blueberry’) print(fruits)
64 / 134
下記のコードを実行した結果として正しいものを選択してください。 tup = (10, 20, 30, 40) new_tup = tup[:2] + (50,) + tup[3:] print(new_tup)
65 / 134
下記のコードを実行した結果として正しいものを選択してください。 person = {‘name’: ‘Alice’, ‘age’: 25, ‘location’: ‘New York’} def update_info(dictionary): dictionary[‘age’] = 30 return dictionary
updated_person = update_info(person) print(updated_person[‘age’])
66 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = [‘apple’, ‘banana’, ‘cherry’, ‘date’] fruits[2] = ‘orange’ print(fruits)
67 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = [‘apple’, ‘banana’, ‘cherry’, ‘date’, ‘elderberry’, ‘fig’, ‘grape’] result = fruits[1:5]
68 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [2, 4, 6, 8, 10] reversed_numbers = numbers[::-1] print(reversed_numbers)
69 / 134
下記のコードを実行した結果として正しいものを選択してください。 my_list = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’] result = my_list[-4:-1] print(result)
70 / 134
下記のコードを実行した結果として正しいものを選択してください。 tup = (10, 20, 30, 40, 50) tup = tup[:-2] + (60,) print(tup)
71 / 134
下記のコードを実行した結果として正しいものを選択してください。 my_dict = {‘apple’: 1, ‘banana’: 2, ‘cherry’: 3} for key in my_dict.keys(): my_dict[key] *= 2
print(my_dict)
72 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [2, 4, 6, 8, 10, 12, 14] result = numbers[-4:-1] print(result)
73 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = [‘apple’, ‘banana’, ‘cherry’, ‘date’] fruits.pop(1) print(fruits)
74 / 134
下記のコードを実行した結果として正しいものを選択してください。 person = {‘name’: ‘Alice’, ‘age’: 25, ‘city’: ‘New York’} person[‘city’] = ‘Los Angeles’ print(person)
75 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = {‘apple’: 3, ‘banana’: 1, ‘cherry’: 5} fruits[‘banana’] += 2 result = fruits.get(‘banana’) print(result)
76 / 134
下記のコードを実行した結果として正しいものを選択してください。 my_list = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’] print(my_list[2:5])
77 / 134
78 / 134
下記のコードを実行した結果として正しいものを選択してください。 person = {‘name’: ‘Alice’, ‘age’: 25, ‘job’: ‘Engineer’} person[‘age’] = 30 person[‘job’] = ‘Manager’ print(person)
79 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = {‘apple’: 100, ‘banana’: 200, ‘cherry’: 300} fruits[‘banana’] = 250 result = fruits[‘banana’] + fruits.get(‘orange’, 0) print(result)
80 / 134
下記のコードを実行した結果として正しいものを選択してください。 my_dict = {‘apple’: 1, ‘banana’: 2, ‘cherry’: 3}
result = my_dict.get(‘banana’, ‘Not Found’) * my_dict.get(‘cherry’, ‘Not Found’)
81 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [2, 4, 6, 8, 10] for n in numbers: if n % 3 == 0: print(‘3の倍数が見つかりました。’) break else: print(‘3の倍数はありませんでした。’)
82 / 134
下記のコードを実行した結果として正しいものを選択してください。 temperature = 30 weather = ‘rainy’
if temperature > 25: if weather == ‘sunny’: activity = ‘swimming’ else: activity = ‘watching a movie’ elif temperature > 15: activity = ‘walking’ else: activity = ‘reading’
print(activity)
83 / 134
下記のコードを実行した結果として正しいものを選択してください。 total = 0 for i in range(1, 10, 2): total += i print(total)
84 / 134
下記のコードを実行した結果として正しいものを選択してください。 number = 25 if number % 2 == 0: result = ‘偶数です。’ else: result = ‘奇数です。’ print(result)
85 / 134
下記のコードを実行した結果として正しいものを選択してください。 names = [‘Alice’, ‘Bob’, ‘Charlie’] ages = [24, 50, 18]
for name, age in zip(names, ages): print(f'{name} is {age} years old.’)
86 / 134
下記のコードを実行した結果として正しいものを選択してください。 from itertools import combinations
items = [‘apple’, ‘banana’, ‘cherry’] comb = list(combinations(items, 2))
result = [] for c in comb: result.append(‘ and ‘.join(c))
print(‘n’.join(result))
87 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = {‘apple’: 2, ‘banana’: 5, ‘cherry’: 7} total = 0 for fruit, quantity in fruits.items(): total += quantity
print(total)
88 / 134
下記のコードを実行した結果として正しいものを選択してください。 age = 20 if age >= 18: status = ‘adult’ else: status = ‘minor’
print(status)
89 / 134
下記のコードを実行した結果として正しいものを選択してください。 total = 0 for i in range(1, 11, 2): total += i
90 / 134
下記のコードを実行した結果として正しいものを選択してください。 score = 75 result = ” if score >= 90: result = ‘Excellent’ elif score >= 80: result = ‘Good’ elif score >= 70: result = ‘Average’ else: result = ‘Poor’
91 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [2, 4, 6, 8, 10] for n in numbers: if n % 2 != 0: print(‘奇数が見つかりました。’) break else: print(‘奇数は見つかりませんでした。’)
92 / 134
items = [‘a’, ‘b’, ‘c’, ‘d’] result = [] for combo in combinations(items, 2): result.append(combo)
93 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = {‘apple’: 1, ‘banana’: 2, ‘cherry’: 3} result = ” for fruit, quantity in fruits.items(): result += f'{fruit}:{quantity} ‘
print(result.strip())
94 / 134
下記のコードを実行した結果として正しいものを選択してください。 n = 5 result = 1 while n > 0: result *= n n -= 1
95 / 134
下記のコードを実行した結果として正しいものを選択してください。 names = [‘Alice’, ‘Bob’, ‘Charlie’] departments = [‘Engineering’, ‘Sales’, ‘Marketing’]
for name, department in zip(names, departments): print(f'{name} works in {department}’)
96 / 134
下記のコードを実行した結果として正しいものを選択してください。 counter = 5 while counter > 0: print(‘Counter:’, counter) counter -= 1
97 / 134
下記のクラス定義とその利用例に基づいて、出力結果として正しいものを選択してください。 class Person: def __init__(self, name): self.name = name
def say_hello(self): return ‘Hello, my name is ‘ + self.name
# Person クラスのインスタンスを作成 person1 = Person(‘Alice’) person2 = Person(‘Bob’)
# say_hello メソッドを呼び出す print(person1.say_hello()) print(person2.say_hello())
出力結果:
98 / 134
下記のコードを実行した結果として正しいものを選択してください。 class BaseClass: def __init__(self): self.base_value = ‘Base’
class SubClass(BaseClass): def __init__(self): super().__init__() self.sub_value = ‘Sub’
obj = SubClass() print(obj.base_value, obj.sub_value)
99 / 134
下記のコードを実行した結果として正しいものを選択してください。 class CustomClass: def __init__(self, value): self.value = value
def multiply_by_two(self): return self.value * 2
obj = CustomClass(5) result = dir(obj)
# result変数の内容を考慮したうえでの選択肢
100 / 134
下記のコードを実行した結果として正しいものを選択してください。 class MyClass: def __init__(self, number): self._number = number def get_number(self): return self._number
obj = MyClass(5) print(obj.get_number()) obj._number = 10 print(obj.get_number())
101 / 134
下記のコードを実行した結果として正しいものを選択してください。 class Animal: def __init__(self, species): self.species = species
def make_sound(self): return ‘Some generic sound’
class Dog(Animal): def __init__(self, name): super().__init__(‘Dog’) self.name = name
def make_sound(self): return ‘Woof!’
my_pet = Dog(‘Buddy’) print(my_pet.species) print(my_pet.name) print(my_pet.make_sound())
102 / 134
下記のコードにおいて、クラスメソッド`get_count`を正しく実行するためのコードとして正しいものを選択してください。 class MyCounter: _count = 0
def __init__(self): MyCounter._count += 1
@classmethod def get_count(cls): return cls._count
# ここでMyCounterクラスのオブジェクトを3つ生成 c1 = MyCounter() c2 = MyCounter() c3 = MyCounter()
# クラスメソッド`get_count`を実行するコード result = [①]
103 / 134
下記のコードを実行した結果として正しいものを選択してください。 class Car: def __init__(self, color): self.color = color
def describe(self): return f’The car is {self.color}’
my_car = Car(‘blue’) print(my_car.describe())
104 / 134
下記のコードを実行した結果として正しいものを選択してください。 class Car: count = 0
def __init__(self, brand): self.brand = brand Car.count += 1
@classmethod def get_count(cls): return cls.count
# Carオブジェクトを3つ作成 car1 = Car(‘Toyota’) car2 = Car(‘Honda’) car3 = Car(‘Nissan’)
# クラスメソッドget_countを用いてCarクラスのオブジェクトの数を取得 print(Car.get_count())
105 / 134
下記のコードを実行した結果として正しいものを選択してください。 class MyClass: def __init__(self, value): self.value = value
def increment(self): self.value += 1
obj = MyClass(5) dir_result = dir(obj)
# dir_resultの内容から’increment’と’value’を含むかどうかをチェック contains_increment = ‘increment’ in dir_result contains_value = ‘value’ in dir_result
print(contains_increment, contains_value)
106 / 134
下記のコードを実行した結果として正しいものを選択してください。 class Circle: def __init__(self, radius): self._radius = radius
@property def radius(self): return self._radius
@radius.setter def radius(self, value): if value >= 0: self._radius = value else: raise ValueError(‘Radius must be non-negative’)
@property def diameter(self): return self._radius * 2
@diameter.setter def diameter(self, value): self.radius = value / 2
def area(self): return 3.14159 * self._radius ** 2
c = Circle(5) print(‘Radius:’, c.radius) c.radius = 10 print(‘Diameter:’, c.diameter) c.diameter = 20 print(‘New Radius:’, c.radius) print(‘Area:’, c.area())
107 / 134
下記のコードを実行した結果として正しいものを選択してください。 class Animal: def speak(self): return ‘I am an animal’
class Dog(Animal): def speak(self): return ‘I am a dog’
class Cat(Animal): def speak(self): return super().speak()
animal = Animal() dog = Dog() cat = Cat()
print(animal.speak()) print(dog.speak()) print(cat.speak())
108 / 134
下記のコードを実行した結果として正しいものを選択してください。 class Vehicle: def __init__(self, wheels, type): self.wheels = wheels self.type = type
def get_vehicle_type(self): return self.type
class Car(Vehicle): def __init__(self, wheels, type, brand): super().__init__(wheels, type) self.brand = brand
def get_vehicle_info(self): return f'{self.brand} {self.type} with {self.wheels} wheels’
my_car = Car(4, ‘Sedan’, ‘Toyota’) print(my_car.get_vehicle_info())
109 / 134
下記のコードを実行した結果として正しいものを選択してください。 class MyClass: def __init__(self, value=0): self._value = value
def increment(self): self._value += 1
def get_value(self): return self._value
obj1 = MyClass(5) obj2 = MyClass() obj1.increment() obj2.increment() obj1.increment()
result1 = obj1.get_value() result2 = obj2.get_value()
110 / 134
@radius.setter def radius(self, value): if value >= 0: self._radius = value else: raise ValueError(‘Radius cannot be negative’)
c = Circle(5) c.radius = 10 print(c.radius) c.radius = -3
111 / 134
下記のコードの空欄①に入る記述として正しいものを選択してください。 class Vehicle: def __init__(self, wheels, capacity): self.wheels = wheels self.capacity = capacity
def display_info(self): print(f’This vehicle has {self.wheels} wheels and a capacity of {self.capacity} people.’)
class Car(Vehicle): def __init__(self, wheels, capacity, brand): super().__init__(wheels, capacity) self.brand = brand
def display_info(self): print(f’This car is made by {self.brand} and has {self.wheels} wheels.’)
class ElectricCar(Car): def __init__(self, wheels, capacity, brand, battery_size): super().__init__(wheels, capacity, brand) self.battery_size = battery_size
def display_info(self): print(f’This electric car is made by {self.brand}, has {self.wheels} wheels and a {self.battery_size} kWh battery.’)
my_vehicle = Vehicle(4, 5) my_car = Car(4, 5, ‘Toyota’) my_electric_car = ElectricCar(4, 5, ‘Tesla’, 85)
my_vehicle.display_info() my_car.display_info() ①
112 / 134
下記のコードを実行した結果として正しいものを選択してください。 class Vehicle: def __init__(self, name, max_speed): self.name = name self.max_speed = max_speed
def get_info(self): return f'{self.name} can go up to {self.max_speed} km/h’
class Car(Vehicle): def __init__(self, name, max_speed, mileage): super().__init__(name, max_speed) self.mileage = mileage
def get_car_info(self): return f'{self.get_info()} and has a mileage of {self.mileage} km/l’
my_car = Car(‘Tesla Model 3’, 225, 15) print(my_car.get_car_info())
113 / 134
下記のコードを実行した結果として正しいものを選択してください。 class Animal: def speak(self): return “I am an animal”
class Dog(Animal): def speak(self): return “Woof!”
class Cat(Animal): def speak(self): return “Meow!”
def animal_sound(animal): print(animal.speak())
my_dog = Dog() my_cat = Cat() animal_sound(my_dog) animal_sound(my_cat)
114 / 134
下記のコードを実行した結果として正しいものを選択してください。 class Vehicle: def __init__(self, name, wheels): self.name = name self.wheels = wheels
def __str__(self): return f'{self.name} has {self.wheels} wheels’
bike = Vehicle(‘Bicycle’, 2) car = Vehicle(‘Car’, 4)
print(bike) print(car)
115 / 134
下記のコードを実行した結果として正しいものを選択してください。 class Vehicle: def __init__(self, wheels, color): self.wheels = wheels self.color = color
class Car(Vehicle): def __init__(self, wheels, color, brand): super().__init__(wheels, color) self.brand = brand
my_car = Car(4, ‘red’, ‘Toyota’) print(f’My car is a {my_car.color} {my_car.brand} with {my_car.wheels} wheels.’)
116 / 134
下記のコードを実行した結果として正しいものを選択してください。 class Parent: def __init__(self): self.value = ‘Inside Parent’
class Child(Parent): def __init__(self): super().__init__() self.value = ‘Inside Child’
child_obj = Child() print(child_obj.value)
117 / 134
下記のコードを実行した結果として正しいものを選択してください。 name = ‘Alice’ age = 30 message = f'{name} is {age} years old.’
print(message)
118 / 134
下記のコードを実行した結果として正しいものを選択してください。 words = [‘banana’, ‘pie’, ‘Washington’, ‘book’] words.sort(key=lambda s: len(s)) print(words)
119 / 134
下記のコードを実行した結果として正しいものを選択してください。 words = [‘apple’, ‘banana’, ‘cherry’, ‘date’] word_lengths = {word: len(word) for word in words} print(word_lengths)
120 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = {‘apple’: 2, ‘banana’: 4, ‘cherry’: 6} fruit_count = 0 for fruit in fruits.keys(): fruit_count += fruits[fruit]
print(fruit_count)
121 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] even_squares = [x**2 for x in numbers if x % 2 == 0] print(even_squares)
122 / 134
下記のコードを実行した結果として正しいものを選択してください。 words = [‘banana’, ‘pie’, ‘Washington’, ‘book’] words.sort(key=lambda x: len(x)) print(words)
123 / 134
下記のコードを実行した結果として正しいものを選択してください。 def func(a, b, c): return a * b * c
values = {‘a’: 2, ‘b’: 3, ‘c’: 4} result = func(*values)
124 / 134
下記のコードを実行した結果として正しいものを選択してください。 def calculate_square_root(x): try: result = x ** 0.5 if str(result).endswith(‘.0’): result = int(result) except TypeError: result = ‘Error: Invalid input type.’ return result
print(calculate_square_root(9)) print(calculate_square_root(’16’)) print(calculate_square_root(-4))
125 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [1, 2, 3, 4, 5] doubled = map(lambda x: x * 2, numbers) print(list(doubled))
126 / 134
下記のコードを実行した結果として正しいものを選択してください。 words = [‘Hello’, ‘World’, ‘Python’, ‘Dictionary’] result = {word: len(word) for word in words if ‘o’ in word} print(result)
127 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] even_squares = [x**2 for x in numbers if x % 2 == 0]
print(even_squares)
128 / 134
下記のコードを実行した結果として正しいものを選択してください。 def greeting(name, greeting_phrase=’Hello’): return f'{greeting_phrase}, {name}!’
user_info = {‘name’: ‘Alice’, ‘greeting_phrase’: ‘Good morning’} result = greeting(**user_info)
129 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] evens_squared = [x*x for x in numbers if x % 2 == 0] print(evens_squared)
130 / 134
下記のコードを実行した結果として正しいものを選択してください。 name = ‘Alice’ greeting = f”Hello, {name}!” print(greeting)
131 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits_count = {‘apples’: 2, ‘bananas’: 3, ‘cherries’: 5} for fruit in fruits_count.keys(): fruits_count[fruit] += 1
print(fruits_count)
132 / 134
下記のコードを実行した結果として正しいものを選択してください。 try: print(‘Trying to open a file…’) file = open(‘non_existent_file.txt’, ‘r’) print(‘File opened successfully!’) except FileNotFoundError as e: print(‘An error occurred:’, e)
print(‘Program ended.’)
133 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] evens_squared = [x * x for x in numbers if x % 2 == 0] print(evens_squared)
134 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [1, 2, 3, 4, 5] doubled_numbers = list(map(lambda x: x * 2, numbers)) print(doubled_numbers)
あなたのスコアは
平均スコアは 0%
メールアドレスが公開されることはありません。 ※ が付いている欄は必須項目です
コメント ※
名前 ※
メール ※
サイト
次回のコメントで使用するためブラウザーに自分の名前、メールアドレス、サイトを保存する。
コメントを残す