一般社団法人 ITエンジニア育成検定協会
Python技術試験 公式模試問題集 1 / 134 下記のコードを実行した結果として正しいものを選択してください。 name = ‘Alice’ age = 30 message = f'{name} is {age} years old.’ print(message) 1. Alice is 30 years old. 2. name is age years old. 3. Alice is {age} years old. 4. {name} is 30 years old. 2 / 134 下記のコードを実行した結果として正しいものを選択してください。 words = [‘banana’, ‘pie’, ‘Washington’, ‘book’] words.sort(key=lambda s: len(s)) print(words) 1. [‘pie’, ‘book’, ‘banana’, ‘Washington’] 2. [‘banana’, ‘pie’, ‘book’, ‘Washington’] 3. [‘Washington’, ‘banana’, ‘pie’, ‘book’] 4. [‘book’, ‘pie’, ‘banana’, ‘Washington’] 3 / 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) 1. [4, 16, 36, 64, 100] 2. [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] 3. [2, 4, 6, 8, 10] 4. [1, 9, 25, 49, 81] 4 / 134 下記のコードを実行した結果として正しいものを選択してください。 name = ‘Alice’ greeting = f”Hello, {name}!” print(greeting) 1. Hello, Alice! 2. Hello, {name}! 3. Hello, ! 4. name 5 / 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) 1. [4, 16, 36, 64, 100] 2. [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] 3. [2, 4, 6, 8, 10] 4. [1, 9, 25, 49, 81] 6 / 134 下記のコードを実行した結果として正しいものを選択してください。 def greeting(name, greeting_phrase=’Hello’): return f'{greeting_phrase}, {name}!’ user_info = {‘name’: ‘Alice’, ‘greeting_phrase’: ‘Good morning’} result = greeting(**user_info) print(result) 1. Good morning, Alice! 2. Hello, Alice! 3. Good morning, {‘name’: ‘Alice’, ‘greeting_phrase’: ‘Good morning’}! 4. SyntaxErrorが発生します。 7 / 134 下記のコードを実行した結果として正しいものを選択してください。 numbers = [1, 2, 3, 4, 5] doubled = map(lambda x: x * 2, numbers) print(list(doubled)) 1. [2, 4, 6, 8, 10] 2. [1, 4, 9, 16, 25] 3. [2, 3, 4, 5, 6] 4. [0, 2, 4, 6, 8] 8 / 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.’) 1. An error occurred: [Errno 2] No such file or directory: ‘non_existent_file.txt’ Program ended. 2. Trying to open a file… File opened successfully! Program ended. 3. An error occurred: FileNotFoundError Program ended. 4. Trying to open a file… An error occurred. Program ended. 9 / 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) 1. [4, 16, 36, 64, 100] 2. [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] 3. [1, 9, 25, 49, 81] 4. [2, 4, 6, 8, 10] 10 / 134 下記のコードを実行した結果として正しいものを選択してください。 words = [‘banana’, ‘pie’, ‘Washington’, ‘book’] words.sort(key=lambda x: len(x)) print(words) 1. [‘pie’, ‘book’, ‘banana’, ‘Washington’] 2. [‘banana’, ‘pie’, ‘book’, ‘Washington’] 3. [‘Washington’, ‘banana’, ‘book’, ‘pie’] 4. [‘book’, ‘pie’, ‘banana’, ‘Washington’] 11 / 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) 1. [4, 16, 36, 64, 100] 2. [1, 9, 25, 49, 81] 3. [2, 4, 6, 8, 10] 4. [1, 4, 9, 16, 25] 12 / 134 下記のコードを実行した結果として正しいものを選択してください。 fruits = {‘apple’: 2, ‘banana’: 4, ‘cherry’: 6} fruit_count = 0 for fruit in fruits.keys(): fruit_count += fruits[fruit] print(fruit_count) 1. 12 2. 3 3. 6 4. 14 13 / 134 下記のコードを実行した結果として正しいものを選択してください。 numbers = [1, 2, 3, 4, 5] doubled_numbers = list(map(lambda x: x * 2, numbers)) print(doubled_numbers) 1. [2, 4, 6, 8, 10] 2. [1, 4, 9, 16, 25] 3. [2, 3, 6, 8, 10] 4. [0, 2, 4, 6, 8] 14 / 134 下記のコードを実行した結果として正しいものを選択してください。 fruits_count = {‘apples’: 2, ‘bananas’: 3, ‘cherries’: 5} for fruit in fruits_count.keys(): fruits_count[fruit] += 1 print(fruits_count) 1. {‘apples’: 3, ‘bananas’: 4, ‘cherries’: 6} 2. {‘apples’: 2, ‘bananas’: 3, ‘cherries’: 5} 3. {‘apples’: 4, ‘bananas’: 5, ‘cherries’: 7} 4. Error 15 / 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)) 1. 3 Error: Invalid input type. (2+0j) 2. 3.0 Error: Invalid input type. (2+0j) 3. 3 Error: Invalid input type. Error: Invalid input type. 4. 3.0 16 Error: Invalid input type. 16 / 134 下記のコードを実行した結果として正しいものを選択してください。 words = [‘apple’, ‘banana’, ‘cherry’, ‘date’] word_lengths = {word: len(word) for word in words} print(word_lengths) 1. {‘apple’: 5, ‘banana’: 6, ‘cherry’: 6, ‘date’: 4} 2. {‘apple’: 5, ‘banana’: 6, ‘cherry’: 7, ‘date’: 4} 3. [‘apple’: 5, ‘banana’: 6, ‘cherry’: 6, ‘date’: 4] 4. {‘apple’: ‘5’, ‘banana’: ‘6’, ‘cherry’: ‘6’, ‘date’: ‘4’} 17 / 134 下記のコードを実行した結果として正しいものを選択してください。 words = [‘Hello’, ‘World’, ‘Python’, ‘Dictionary’] result = {word: len(word) for word in words if ‘o’ in word} print(result) 1. {‘Hello’: 5, ‘World’: 5, ‘Python’: 6} 2. {‘Hello’: 5, ‘World’: 5} 3. {‘words’: 5, ‘Python’: 6} 4. {‘Hello’: 2, ‘World’: 1, ‘Python’: 1} 18 / 134 下記のコードを実行した結果として正しいものを選択してください。 def func(a, b, c): return a * b * c values = {‘a’: 2, ‘b’: 3, ‘c’: 4} result = func(*values) print(result) 1. 24 2. 9 3. TypeErrorが発生する 4. func関数が定義されていないエラーが発生する 19 / 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) 1. [1, 3, 5, 7, 9] 2. [2, 4, 6, 8, 10] 3. [1, 2, 3, 4, 5] 4. [‘is_odd’, 1, 3, 5, 7, 9] 20 / 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}’) 1. The value of pi is 3.141592653589793 and the current working directory is 表示される現在の作業ディレクトリのパス 2. エラーが発生する 3. The value of pi is math.pi and the current working directory is os.getcwd() 4. 何も出力されない 21 / 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) 1. Sort: [1, 1, 2, 3, 3, 4, 5, 5, 6, 9] Sorted: [9, 6, 5, 5, 4, 3, 3, 2, 1, 1] 2. Sort: [9, 6, 5, 5, 4, 3, 3, 2, 1, 1] Sorted: [1, 1, 2, 3, 3, 4, 5, 5, 6, 9] 3. Sort: [3, 1, 4, 1, 5, 9, 2, 6, 5, 3] Sorted: [1, 1, 2, 3, 3, 4, 5, 5, 6, 9] 4. Sort: [1, 1, 2, 3, 3, 4, 5, 5, 6, 9] Sorted: [1, 1, 2, 3, 3, 4, 5, 5, 6, 9] 22 / 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) 1. 20 2. 25 3. 30 4. 35 23 / 134 下記のコードを実行した結果として正しいものを選択してください。 names = [‘Alice’, ‘Bob’, ‘Charlie’] ages = [24, 50, 18] for name, age in zip(names, ages): print(f'{name} is {age} years old.’) 1. Alice is 24 years old. Bob is 50 years old. Charlie is 18 years old. 2. Alice is 50 years old. Bob is 18 years old. Charlie is 24 years old. 3. [‘Alice’, ‘Bob’, ‘Charlie’] is [24, 50, 18] years old. 4. (‘Alice’, 24) is (‘Bob’, 50) is (‘Charlie’, 18) years old. 24 / 134 下記のコードを実行した結果として正しいものを選択してください。 def concat_strings(*args, sep=’/’): return sep.join(args) result = concat_strings(‘apple’, ‘banana’, ‘cherry’, sep=’, ‘) print(result) 1. apple, banana, cherry 2. apple/banana/cherry 3. apple banana cherry 4. apple;banana;cherry 25 / 134 下記のコードを実行した結果として正しいものを選択してください。 def multiply(a, b=2): return a * b result1 = multiply(3) result2 = multiply(3, 5) print(‘result1:’, result1, ‘result2:’, result2) 1. result1: 6 result2: 15 2. result1: 3 result2: 15 3. result1: 6 result2: 8 4. result1: 9 result2: 15 26 / 134 下記のコードを実行した結果として正しいものを選択してください。 def print_args(*args): for i, arg in enumerate(args): print(f’Argument {i}: {arg}’) print_args(‘Python’, ‘is’, ‘fun’, ‘!’) 1. Argument 0: Python Argument 1: is Argument 2: fun Argument 3: ! 2. Argument 1: Python Argument 2: is Argument 3: fun Argument 4: ! 3. Argument: Python Argument: is Argument: fun Argument: ! 4. Python is fun ! 27 / 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) 1. [2, 4, 6, 8, 10] 2. [1, 3, 5, 7, 9] 3. [0, 2, 4, 6, 8] 4. [1, 2, 3, 4, 5] 28 / 134 下記のコードを実行した結果として正しいものを選択してください。 number = 123456.789 formatted_number = ‘{:,.2f}’.format(number) print(formatted_number) 1. 123,456.79 2. 123456.78 3. 123.456,79 4. 123456,789.00 29 / 134 下記のコードを実行した結果として正しいものを選択してください。 data = [‘Python’, ‘Java’, ‘C++’, ‘JavaScript’] result = len(data[2]) print(result) 1. 3 2. 4 3. 6 4. 8 30 / 134 下記のコードを実行した結果として正しいものを選択してください。 fruits = [‘apple’, ‘banana’, ‘cherry’] fruits.append(‘orange’) print(fruits) 1. [‘apple’, ‘banana’, ‘cherry’, ‘orange’] 2. [‘apple’, ‘banana’, ‘cherry’] 3. [‘orange’, ‘apple’, ‘banana’, ‘cherry’] 4. [‘banana’, ‘cherry’, ‘apple’, ‘orange’] 31 / 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}’) 1. all: False, any: True 2. all: True, any: False 3. all: True, any: True 4. all: False, any: False 32 / 134 下記のコードを実行した結果として正しいものを選択してください。 numbers = [3, 5, 1, 4, 2] max_value = max(numbers) min_value = min(numbers) result = max_value + min_value print(result) 1. 9 2. 6 3. 8 4. 10 33 / 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) 1. 最大値: 22 最小値: 5 平均値: 13.5 2. 最大値: 22 最小値: 5 平均値: 12 3. 最大値: 15 最小値: 8 平均値: 11.5 4. 最大値: 10 最小値: 5 平均値: 7.5 34 / 134 下記のコードを実行した結果として正しいものを選択してください。 my_list = [‘apple’, ‘banana’, ‘cherry’] for item in reversed(my_list): print(item) 1. cherry banana apple 2. apple banana cherry 3. [‘cherry’, ‘banana’, ‘apple’] 4. [‘apple’, ‘banana’, ‘cherry’] 35 / 134 下記のコードを実行した結果として正しいものを選択してください。 numbers = [1, 2, 3, 4, 5] def square(x): return x * x result = map(square, numbers) print(list(result)) 1. [1, 4, 9, 16, 25] 2. [1, 2, 3, 4, 5] 3. [2, 4, 6, 8, 10] 4. [1, 8, 27, 64, 125] 36 / 134 下記のコードを実行した結果として正しいものを選択してください。 names = [‘Alice’, ‘Bob’, ‘Charlie’] ages = [24, 30, 28] for name, age in zip(names, ages): print(f'{name} is {age} years old.’) 1. Alice is 24 years old. Bob is 30 years old. Charlie is 28 years old. 2. [(‘Alice’, 24), (‘Bob’, 30), (‘Charlie’, 28)] 3. [‘Alice is 24’, ‘Bob is 30’, ‘Charlie is 28’] 4. Alice24Bob30Charlie28 37 / 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’)) 1. Hello, Alice! Good morning, Bob! How do you do, Charlie! 2. Hello, Alice! Good morning, Bob! Hello, Charlie! 3. Hello, Alice! Hello, Bob! How do you do, Charlie! 4. Good morning, Alice! Good morning, Bob! How do you do, Charlie! 38 / 134 下記のコードを実行した結果として正しいものを選択してください。 numbers = iter([1, 2, 3]) output = [] while True: try: number = next(numbers) output.append(number) except StopIteration: break print(output) 1. [1, 2, 3] 2. [1, 2] 3. [] 4. [1, 2, 3, StopIteration] 39 / 134 下記のコードを実行した結果として正しいものを選択してください。 from math import sqrt as s, factorial as f result = f(5) / s(25) print(result) 1. 24.0 2. 120.0 3. 5.0 4. 1.0 40 / 134 下記のコードを実行した結果として正しいものを選択してください。 my_string = ‘Python Programming’ my_slice = slice(7, 18) result = my_string[my_slice] print(result) 1. Programming 2. Python 3. Progra 4. thon Progra 41 / 134 下記のコードを実行した結果として正しいものを選択してください。 name = input(‘あなたの名前を教えてください: ‘) age = input(‘あなたの年齢を教えてください: ‘) print(f’こんにちは、{name}さん!あなたは{age}歳ですね。’) 1. 入力された名前と年齢がそれぞれ{name}と{age}の部分に表示される 2. エラーメッセージが表示される 3. 定数文字列’こんにちは、{name}さん!あなたは{age}歳ですね。’がそのまま表示される 4. 入力された名前と年齢が逆の順番で表示される 42 / 134 下記のコードを実行した結果として正しいものを選択してください。 fruits = [‘apple’, ‘banana’, ‘cherry’] fruits.append(‘orange’) print(fruits) 1. [‘apple’, ‘banana’, ‘cherry’, ‘orange’] 2. [‘apple’, ‘banana’, ‘cherry’, ‘orange’, ‘orange’] 3. [‘orange’, ‘apple’, ‘banana’, ‘cherry’] 4. [‘apple’, ‘orange’, ‘banana’, ‘cherry’] 43 / 134 下記のコードを実行した結果として正しいものを選択してください。 iterable = [‘apple’, ‘banana’, ‘cherry’] iterator = iter(iterable) first_item = next(iterator) second_item = next(iterator) third_item = next(iterator) forth_item = next(iterator) 1. StopIteration例外が発生する 2. forth_itemには’cherry’が格納される 3. forth_itemには’apple’が再び格納される 4. forth_itemはNoneになる 44 / 134 下記のコードを実行した結果として正しいものを選択してください。 alphabet = ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’ my_slice = slice(5, 20, 3) result = alphabet[my_slice] print(result) 1. FILOR 2. ABCDE 3. AFKPUZ 4. GJMPSV 45 / 134 下記のコードを実行した結果として正しいものを選択してください。 numbers = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5] numbers.sort() print(numbers) 1. [1, 1, 2, 3, 3, 4, 5, 5, 5, 6, 9] 2. [1, 1, 2, 3, 3, 4, 5, 5, 9, 6, 5] 3. [9, 6, 5, 5, 5, 4, 3, 3, 2, 1, 1] 4. [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5] 46 / 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) 1. [1, 1, 2, 3, 3, 4, 5, 5, 6, 9], [9, 6, 5, 5, 4, 3, 3, 2, 1, 1] 2. [1, 1, 2, 3, 3, 4, 5, 5, 6, 9], [1, 1, 2, 3, 3, 4, 5, 5, 6, 9] 3. [9, 6, 5, 5, 4, 3, 3, 2, 1, 1], [1, 1, 2, 3, 3, 4, 5, 5, 6, 9] 4. [3, 1, 4, 1, 5, 9, 2, 6, 5, 3], [9, 6, 5, 5, 4, 3, 3, 2, 1, 1] 47 / 134 下記のコードを実行した結果として正しいものを選択してください。 name = input(‘あなたの名前を入力してください: ‘) print(‘こんにちは、’ + name + ‘さん!’) 1. ユーザーが入力した名前に応じて挨拶するメッセージが出力される 2. プログラムはエラーを出して停止する 3. 常に「こんにちは、さん!」と出力される 4. 入力を求めるプロンプトが表示されない 48 / 134 下記のコードを実行した結果として正しいものを選択してください。 my_list = [‘apple’, ‘banana’, ‘cherry’, ‘date’] result = len(my_list) print(result) 1. 4 2. 5 3. 3 4. 6 49 / 134 下記のコードを実行した結果として正しいものを選択してください。 number = 1024 formatted_string = ‘{:b}’.format(number) print(formatted_string) 1. 10000000000 2. 1024 3. 0b10000000000 4. 0x400 50 / 134 下記のコードを実行した結果として正しいものを選択してください。 code = “def add(x, y): return x + y” exec(code) result = eval(‘add(2, 3)’) print(result) 1. 5 2. add(2, 3) 3. None 4. SyntaxError 51 / 134 下記のコードを実行した結果として正しいものを選択してください。 def greet(name, greeting=’Hello’): return f'{greeting}, {name}!’ print(greet(‘Alice’)) print(greet(‘Bob’, ‘Good morning’)) print(greet(‘Charlie’, greeting=’Greetings’)) 1. Hello, Alice! Good morning, Bob! Greetings, Charlie! 2. Hello, ! Good morning, Bob! Greetings, Charlie! 3. Hello, Alice! Good morning, Bob! Good morning, Charlie! 4. Hello, Alice! Hello, Bob! Hello, Charlie! 52 / 134 下記のコードを実行した結果として正しいものを選択してください。 numbers = [1, 2, 3, 4, 5] def square(x): return x * x result = map(square, numbers) print(list(result)) 1. [1, 4, 9, 16, 25] 2. [1, 2, 3, 4, 5] 3. [2, 4, 6, 8, 10] 4. [0, 1, 2, 3, 4] 53 / 134 下記のコードを実行した結果として正しいものを選択してください。 code = ‘result = [str(i) for i in range(5)]’ exec(code) print(eval(‘ “+”.join(result) ‘)) 1. 0+1+2+3+4 2. [‘0’, ‘1’, ‘2’, ‘3’, ‘4’] 3. 01234 4. SyntaxError 54 / 134 下記のコードを実行した結果として正しいものを選択してください。 my_list = [‘a’, ‘b’, ‘c’, ‘d’] reversed_list = list(reversed(my_list)) print(reversed_list) 1. [‘d’, ‘c’, ‘b’, ‘a’] 2. [‘a’, ‘b’, ‘c’, ‘d’] 3. [‘d’, ‘a’, ‘b’, ‘c’] 4. [‘c’, ‘b’, ‘a’, ‘d’] 55 / 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) 1. [1, 1, 2, 3, 4, 5, 5, 6, 9]と[‘a’, ‘b’, ‘c’, ‘d’] 2. [9, 6, 5, 5, 4, 3, 2, 1, 1]と[‘d’, ‘c’, ‘b’, ‘a’] 3. [1, 1, 2, 3, 4, 5, 5, 6, 9]と[‘d’, ‘a’, ‘c’, ‘b’] 4. [3, 1, 4, 1, 5, 9, 2, 6, 5]と[‘a’, ‘b’, ‘c’, ‘d’] 56 / 134 下記のコードを実行した結果として正しいものを選択してください。 values = [10, 20, 0, 30] print(all(value > 0 for value in values), any(value > 0 for value in values)) 1. (False, True) 2. (True, False) 3. (True, True) 4. (False, False) 57 / 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()) 1. Radius: 5 Diameter: 20 New Radius: 10 Area: 314.159 2. Radius: 5 Diameter: 10 New Radius: 10 Area: 78.53975 3. Radius: 5 Diameter: 20 New Radius: 10 Area: 78.53975 4. ValueError: Radius must be non-negative 58 / 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()) 1. Toyota Sedan with 4 wheels 2. Car Sedan with 4 wheels 3. Toyota Vehicle with 4 wheels 4. Sedan Car with Toyota wheels 59 / 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) 1. Woof! Meow! 2. I am an animal I am an animal 3. Dog Cat 4. Woof! I am an animal 60 / 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()) 1. 3 2. 1 3. 0 4. 6 61 / 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) 1. Bicycle has 2 wheels Car has 4 wheels 2. Vehicle object at 0x10 Vehicle object at 0x11 3. Bicycle has 4 wheels Car has 2 wheels 4. Bicycle, Car 62 / 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 = [①] print(result) 1. MyCounter.get_count() 2. c1.get_count() 3. MyCounter._count 4. c1._count 63 / 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()) 1. Dog Buddy Woof! 2. Animal Dog Some generic sound 3. None Buddy Woof! 4. Dog None Some generic sound 64 / 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) 1. Base Sub 2. Sub Base 3. Base Base 4. Sub Sub 65 / 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()) 1. The car is blue 2. The car is 3. blue 4. Car(‘blue’) 66 / 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変数の内容を考慮したうえでの選択肢 1. [‘__class__’, ‘__delattr__’, ‘__dict__’, ‘__dir__’, ‘__doc__’, ‘__eq__’, ‘__format__’, ‘__ge__’, ‘__getattribute__’, ‘__gt__’, ‘__hash__’, ‘__init__’, ‘__init_subclass__’, ‘__le__’, ‘__lt__’, ‘__module__’, ‘__ne__’, ‘__new__’, ‘__reduce__’, ‘__reduce_ex__’, ‘__repr__’, ‘__setattr__’, ‘__sizeof__’, ‘__str__’, ‘__subclasshook__’, ‘multiply_by_two’, ‘value’] 2. [‘__init__’, ‘multiply_by_two’, ‘value’] 3. [‘CustomClass’, ‘multiply_by_two’, ‘value’, ‘__init__’] 4. [‘__init__’, ‘multiply_by_two’, ‘value’, ‘__main__’] 67 / 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.’) 1. My car is a red Toyota with 4 wheels. 2. My car is a Toyota with 4 red wheels. 3. My car is a red Vehicle with 4 wheels. 4. The code will raise an AttributeError. 68 / 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) 1. Inside Child 2. Inside Parent 3. super().__init__() 4. Child does not have attribute value 69 / 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 cannot be negative’) c = Circle(5) c.radius = 10 print(c.radius) c.radius = -3 1. ValueErrorが発生する 2. 5が表示される 3. 10が表示される 4. 何も表示されない 70 / 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()) 1. 5 10 2. 5 5 3. 10 10 4. 10 5 71 / 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() ① 1. my_electric_car.display_info() 2. my_electric_car = ElectricCar() 3. my_car = Car() 4. my_vehicle.display_info() 72 / 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()) 出力結果: 1. Hello, my name is Alice Hello, my name is Bob 2. Hello, my name is Bob Hello, my name is Alice 3. Hello, my name is Person Hello, my name is Person 4. my name is Alice my name is Bob 73 / 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()) 1. I am an animal I am a dog I am an animal 2. I am an animal I am an animal I am an animal 3. I am a dog I am a dog I am a dog 4. I am an animal I am a dog I am a cat 74 / 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) 1. True True 2. True False 3. False True 4. False False 75 / 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() 1. {"result1": 7, "result2": 1} 2. {"result1": 6, "result2": 1} 3. {"result1": 7, "result2": 0} 4. {"result1": 6, "result2": 0} 76 / 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()) 1. Tesla Model 3 can go up to 225 km/h and has a mileage of 15 km/l 2. Car(‘Tesla Model 3’, 225, 15) can go up to 225 km/h 3. Vehicle(‘Tesla Model 3’, 225) can go up to 225 km/h and has a mileage of 15 km/l 4. Tesla Model 3 has a mileage of 15 km/l 77 / 134 下記のコードを実行した結果として正しいものを選択してください。 my_dict = {‘apple’: 1, ‘banana’: 2, ‘cherry’: 3} result = my_dict.get(‘banana’, ‘Not Found’) * my_dict.get(‘cherry’, ‘Not Found’) print(result) 1. 6 2. Not Found 3. 5 4. None 78 / 134 下記のコードを実行した結果として正しいものを選択してください。 fruits = {‘apple’: 3, ‘banana’: 1, ‘cherry’: 5} fruits[‘banana’] += 2 result = fruits.get(‘banana’) print(result) 1. 3 2. 1 3. 5 4. 7 79 / 134 下記のコードを実行した結果として正しいものを選択してください。 fruits = [‘apple’, ‘banana’, ‘cherry’, ‘date’] fruits.pop(1) print(fruits) 1. [‘apple’, ‘cherry’, ‘date’] 2. [‘banana’, ‘cherry’, ‘date’] 3. [‘apple’, ‘banana’, ‘date’] 4. [‘apple’, ‘banana’, ‘cherry’] 80 / 134 下記のコードを実行した結果として正しいものを選択してください。 person = {‘name’: ‘Alice’, ‘age’: 25, ‘city’: ‘New York’} person[‘city’] = ‘Los Angeles’ print(person) 1. {‘name’: ‘Alice’, ‘age’: 25, ‘city’: ‘Los Angeles’} 2. {‘name’: ‘Alice’, ‘age’: 25, ‘city’: ‘New York’} 3. {‘name’: ‘Alice’, ‘age’: 25} 4. {‘name’: ‘Alice’, ‘age’: 25, ‘city’: ‘Los Angeles’, ‘city’: ‘New York’} 81 / 134 下記のコードを実行した結果として正しいものを選択してください。 fruits = [‘apple’, ‘banana’, ‘cherry’, ‘date’] fruits[2] = ‘orange’ print(fruits) 1. [‘apple’, ‘banana’, ‘orange’, ‘date’] 2. [‘apple’, ‘orange’, ‘cherry’, ‘date’] 3. [‘apple’, ‘banana’, ‘cherry’, ‘orange’] 4. [‘orange’, ‘banana’, ‘cherry’, ‘date’] 82 / 134 下記のコードを実行した結果として正しいものを選択してください。 numbers = [2, 4, 6, 8, 10] reversed_numbers = numbers[::-1] print(reversed_numbers) 1. [10, 8, 6, 4, 2] 2. [2, 4, 6, 8, 10] 3. [10, 2, 4, 6, 8] 4. [2, 10, 8, 6, 4] 83 / 134 下記のコードを実行した結果として正しいものを選択してください。 numbers = [2, 4, 6, 8, 10] reversed_numbers = numbers[::-1] print(reversed_numbers) 1. [10, 8, 6, 4, 2] 2. [2, 4, 6, 8, 10] 3. [10, 2, 8, 4, 6] 4. [’10’, ‘8’, ‘6’, ‘4’, ‘2’] 84 / 134 下記のコードを実行した結果として正しいものを選択してください。 person = {‘name’: ‘Alice’, ‘age’: 25, ‘job’: ‘Engineer’} person[‘age’] = 30 person[‘job’] = ‘Manager’ print(person) 1. {‘name’: ‘Alice’, ‘age’: 30, ‘job’: ‘Manager’} 2. {‘name’: ‘Alice’, ‘age’: 25, ‘job’: ‘Engineer’} 3. {‘name’: ‘Alice’, ‘age’: 30, ‘job’: ‘Engineer’} 4. {‘name’: ‘Alice’, ‘age’: 25, ‘job’: ‘Manager’} 85 / 134 下記のコードを実行した結果として正しいものを選択してください。 numbers = [2, 4, 6, 8, 10, 12, 14] result = numbers[-4:-1] print(result) 1. [8, 10, 12] 2. [6, 8, 10] 3. [10, 12, 14] 4. [2, 4, 6] 86 / 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’]) 1. 30 2. 25 3. None 4. エラーが発生する 87 / 134 下記のコードを実行した結果として正しいものを選択してください。 tup = (10, 20, 30, 40, 50) tup = tup[:-2] + (60,) print(tup) 1. (10, 20, 30, 60) 2. (10, 20, 60, 40, 50) 3. (10, 20, 30, 40, 50, 60) 4. (10, 20, 60) 88 / 134 下記のコードを実行した結果として正しいものを選択してください。 tup = (10, 20, 30, 40) new_tup = tup[:2] + (50,) + tup[3:] print(new_tup) 1. (10, 20, 50, 40) 2. (10, 20, 30, 50, 40) 3. (10, 50, 20, 40) 4. (10, 20, 30, 50) 89 / 134 下記のコードを実行した結果として正しいものを選択してください。 my_dict = {‘apple’: 1, ‘banana’: 2, ‘cherry’: 3} for key in my_dict.keys(): my_dict[key] *= 2 print(my_dict) 1. {‘apple’: 2, ‘banana’: 4, ‘cherry’: 6} 2. {‘apple’: 1, ‘banana’: 2, ‘cherry’: 3} 3. {‘apple’: 3, ‘banana’: 5, ‘cherry’: 7} 4. {‘apple’: 0, ‘banana’: 0, ‘cherry’: 0} 90 / 134 下記のコードを実行した結果として正しいものを選択してください。 my_list = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’] result = my_list[-4:-1] print(result) 1. [‘d’, ‘e’, ‘f’] 2. [‘c’, ‘d’, ‘e’] 3. [‘e’, ‘f’, ‘g’] 4. [‘a’, ‘b’, ‘c’] 91 / 134 下記のコードを実行した結果として正しいものを選択してください。 fruits = {‘apple’: 10, ‘banana’: 5, ‘cherry’: 15} for fruit in fruits: fruits[fruit] += 5 print(fruits[‘banana’]) 1. 10 2. 15 3. 20 4. 5 92 / 134 下記のコードを実行した結果として正しいものを選択してください。 fruits = [‘apple’, ‘banana’, ‘cherry’, ‘date’, ‘elderberry’, ‘fig’, ‘grape’] result = fruits[1:5] print(result) 1. [‘banana’, ‘cherry’, ‘date’, ‘elderberry’] 2. [‘apple’, ‘banana’, ‘cherry’, ‘date’] 3. [‘banana’, ‘cherry’, ‘date’] 4. [‘cherry’, ‘date’, ‘elderberry’, ‘fig’] 93 / 134 下記のコードを実行した結果として正しいものを選択してください。 fruits = {‘apple’: 100, ‘banana’: 200, ‘cherry’: 300} fruits[‘banana’] = 250 result = fruits[‘banana’] + fruits.get(‘orange’, 0) print(result) 1. 250 2. 450 3. 200 4. 300 94 / 134 下記のコードを実行した結果として正しいものを選択してください。 fruits = [‘apple’, ‘banana’, ‘cherry’, ‘date’] fruits.pop(1) fruits.insert(1, ‘blueberry’) print(fruits) 1. [‘apple’, ‘blueberry’, ‘cherry’, ‘date’] 2. [‘apple’, ‘banana’, ‘blueberry’, ‘date’] 3. [‘apple’, ‘cherry’, ‘date’] 4. [‘apple’, ‘blueberry’, ‘cherry’] 95 / 134 下記のコードを実行した結果として正しいものを選択してください。 my_list = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’] print(my_list[2:5]) 1. [‘c’, ‘d’, ‘e’] 2. [‘b’, ‘c’, ‘d’, ‘e’] 3. [‘a’, ‘b’, ‘c’, ‘d’] 4. [‘c’, ‘d’, ‘e’, ‘f’] 96 / 134 下記のコードを実行した結果として正しいものを選択してください。 fruits = [‘apple’, ‘banana’, ‘cherry’, ‘date’] removed_item = fruits.pop(2) print(‘Removed:’, removed_item) print(‘Remaining fruits:’, fruits) 1. {"Removed:": "cherry", "Remaining fruits:": ["apple", "banana", "date"]} 2. {"Removed:": "banana", "Remaining fruits:": ["apple", "cherry", "date"]} 3. {"Removed:": "date", "Remaining fruits:": ["apple", "banana", "cherry"]} 4. {"Removed:": "apple", "Remaining fruits:": ["banana", "cherry", "date"]} 97 / 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) 1. a = 30 a = 20 a = 10 2. a = 20 a = 30 a = 10 3. a = 10 a = 20 a = 30 4. a = 30 a = 30 a = 30 98 / 134 下記のコードを実行した結果として正しいものを選択してください。 x = 10 def increment(): global x x += 1 increment() print(x) 1. 11 2. 10 3. エラーになる 4. None 99 / 134 下記のコードを実行した結果として正しいものを選択してください。 x = ‘7.5’ y = int(float(x)) print(y) 1. 7 2. 7.5 3. 8 4. TypeErrorが発生します 100 / 134 下記のコードを実行した結果として正しいものを選択してください。 x = ‘100’ y = 200 z = float(x) + y print(z) 1. 300.0 2. 100200 3. ‘100200’ 4. TypeError 101 / 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) 1. a = 30 a = 20 a = 10 2. a = 30 a = 30 a = 30 3. a = 20 a = 20 a = 10 4. a = 10 a = 20 a = 30 102 / 134 下記のコードを実行した結果として正しいものを選択してください。 values = [0, ”, [], {}, set(), ‘False’, False, 1, -1] count_true = 0 for v in values: count_true += bool(v) print(count_true) 1. 3 2. 4 3. 5 4. 6 103 / 134 下記のコードを実行した結果として正しいものを選択してください。 number_str = ‘3.14’ number_float = float(number_str) number_int = int(number_float) print(number_int) 1. 3 2. 3.14 3. ‘3.14’ 4. エラーが発生する 104 / 134 下記のコードを実行した結果として正しいものを選択してください。 a = 7 b = 3 a *= b print(a) 1. 21 2. 10 3. 7 4. 3 105 / 134 下記のコードを実行した結果として正しいものを選択してください。 number = 256 binary_str = bin(number) hex_str = hex(number) print(‘Binary:’, binary_str, ‘Hexadecimal:’, hex_str) 1. Binary: 0b100000000 Hexadecimal: 0x100 2. Binary: 0b100000000 Hexadecimal: 0x80 3. Binary: 0b1000000 Hexadecimal: 0x100 4. Binary: 0b1000000 Hexadecimal: 0x80 106 / 134 下記のコードを実行した結果として正しいものを選択してください。 x = 7 y = 2 print(‘The result of 7 // 2 is:’, x // y) 1. The result of 7 // 2 is: 3 2. The result of 7 // 2 is: 3.5 3. The result of 7 // 2 is: 4 4. The result of 7 // 2 is: 14 107 / 134 下記のコードを実行した結果として正しいものを選択してください。 a = 10 b = 20 c = ’30’ d = a + b + int(c) print(d) 1. 60 2. 102030 3. 30 4. None 108 / 134 下記のコードを実行した結果として正しいものを選択してください。 a = 5 b = 10 a = b b = a + b print(a, b) 1. 10 20 2. 5 15 3. 10 15 4. 5 10 109 / 134 下記のコードを実行した結果として正しいものを選択してください。 a = 5 b = 10 c = b b = a a = c print(‘a =’, a, ‘b =’, b) 1. a = 10 b = 5 2. a = 5 b = 5 3. a = 5 b = 10 4. a = 10 b = 10 110 / 134 下記のコードを実行した結果として正しいものを選択してください。 a = 8 b = 3 c = a ** b print(c) 1. 512 2. 11 3. 24 4. 64 111 / 134 下記のコードを実行した結果として正しいものを選択してください。 x = 5 y = 3 print(f'{x} + {y} = {x + y}’) 1. 5 + 3 = 8 2. 5 + 3 = 5 3. 8 4. x + y = 8 112 / 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) 1. Inner a: 30nOuter a: 20nGlobal a: 10 2. Inner a: 30nOuter a: 30nGlobal a: 10 3. Inner a: 20nOuter a: 20nGlobal a: 10 4. Inner a: 10nOuter a: 20nGlobal a: 10 113 / 134 下記のコードを実行した結果として正しいものを選択してください。 number1 = 10 number2 = 20 result = number1 * number2 print(result) 1. 200 2. 30 3. 10 4. None 114 / 134 下記のコードを実行した結果として正しいものを選択してください。 num_str = ‘7.25’ num_int = int(float(num_str)) print(num_int) 1. 7 2. 7.25 3. エラーになる 4. 7.0 115 / 134 下記のコードを実行した結果として正しいものを選択してください。 a = 10 b = 5 c = ‘2’ d = a + b * int(c) print(d) 1. 20 2. 60 3. 15 4. 102 116 / 134 下記のコードを実行した結果として正しいものを選択してください。 x = 5 y = 2 print(x ** y) 1. 25 2. 10 3. 7 4. 2.5 117 / 134 下記のコードを実行した結果として正しいものを選択してください。 values = [0, ”, ‘Python’, [], {}, [1, 2, 3], {1: ‘one’}, None, False, True] results = [bool(value) for value in values] print(results) 1. [False, False, True, False, False, True, True, False, False, True] 2. [True, True, True, True, True, True, True, True, True, True] 3. [False, False, False, False, False, False, False, False, False, False] 4. [None, ”, ‘Python’, [], {}, [1, 2, 3], {1: ‘one’}, None, False, True] 118 / 134 下記のコードを実行した結果として正しいものを選択してください。 number = 7.25 print(int(number)) 1. 7 2. 8 3. 7.0 4. 7.25 119 / 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) 1. watching a movie 2. swimming 3. walking 4. reading 120 / 134 下記のコードを実行した結果として正しいものを選択してください。 numbers = [2, 4, 6, 8, 10] for n in numbers: if n % 3 == 0: print(‘3の倍数が見つかりました。’) break else: print(‘3の倍数はありませんでした。’) 1. 3の倍数はありませんでした。 2. 3の倍数が見つかりました。 3. エラーが発生します。 4. 何も出力されません。 121 / 134 下記のコードを実行した結果として正しいものを選択してください。 names = [‘Alice’, ‘Bob’, ‘Charlie’] departments = [‘Engineering’, ‘Sales’, ‘Marketing’] for name, department in zip(names, departments): print(f'{name} works in {department}’) 1. Alice works in Engineering Bob works in Sales Charlie works in Marketing 2. Alice works in Sales Bob works in Marketing Charlie works in Engineering 3. Alice, Bob, Charlie works in Engineering, Sales, Marketing 4. The code will raise an error because the lists have different lengths 122 / 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)) 1. apple and banana apple and cherry banana and cherry 2. apple, banana apple, cherry banana, cherry 3. apple banana cherry 4. apple and apple banana and banana cherry and cherry 123 / 134 下記のコードを実行した結果として正しいものを選択してください。 score = 75 result = ” if score >= 90: result = ‘Excellent’ elif score >= 80: result = ‘Good’ elif score >= 70: result = ‘Average’ else: result = ‘Poor’ print(result) 1. Average 2. Good 3. Excellent 4. Poor 124 / 134 下記のコードを実行した結果として正しいものを選択してください。 names = [‘Alice’, ‘Bob’, ‘Charlie’] ages = [24, 50, 18] for name, age in zip(names, ages): print(f'{name} is {age} years old.’) 1. Alice is 24 years old. Bob is 50 years old. Charlie is 18 years old. 2. Alice is 24 years old. Bob is 50 years old. 3. [‘Alice’, ‘Bob’, ‘Charlie’] are [24, 50, 18] years old. 4. Error: The zip function cannot be used in a for loop. 125 / 134 下記のコードを実行した結果として正しいものを選択してください。 fruits = {‘apple’: 1, ‘banana’: 2, ‘cherry’: 3} result = ” for fruit, quantity in fruits.items(): result += f'{fruit}:{quantity} ‘ print(result.strip()) 1. apple:1 banana:2 cherry:3 2. apple banana cherry 3. 1 2 3 4. fruit:1 fruit:2 fruit:3 126 / 134 下記のコードを実行した結果として正しいものを選択してください。 n = 5 result = 1 while n > 0: result *= n n -= 1 print(result) 1. 120 2. 24 3. 0 4. 5 127 / 134 下記のコードを実行した結果として正しいものを選択してください。 counter = 5 while counter > 0: print(‘Counter:’, counter) counter -= 1 1. Counter: 5 Counter: 4 Counter: 3 Counter: 2 Counter: 1 2. Counter: 1 Counter: 2 Counter: 3 Counter: 4 Counter: 5 3. Counter: 4 Counter: 3 Counter: 2 Counter: 1 Counter: 0 4. エラーが発生する 128 / 134 下記のコードを実行した結果として正しいものを選択してください。 total = 0 for i in range(1, 11, 2): total += i print(total) 1. 25 2. 30 3. 20 4. 55 129 / 134 下記のコードを実行した結果として正しいものを選択してください。 number = 25 if number % 2 == 0: result = ‘偶数です。’ else: result = ‘奇数です。’ print(result) 1. 奇数です。 2. 偶数です。 3. エラーが発生します。 4. 何も出力されません。 130 / 134 下記のコードを実行した結果として正しいものを選択してください。 fruits = {‘apple’: 2, ‘banana’: 5, ‘cherry’: 7} total = 0 for fruit, quantity in fruits.items(): total += quantity print(total) 1. 14 2. 3 3. {‘apple’: 2, ‘banana’: 5, ‘cherry’: 7} 4. ‘applebananacherry’ 131 / 134 下記のコードを実行した結果として正しいものを選択してください。 age = 20 if age >= 18: status = ‘adult’ else: status = ‘minor’ print(status) 1. ‘adult’ 2. ‘minor’ 3. 18 4. ‘status’ 132 / 134 下記のコードを実行した結果として正しいものを選択してください。 from itertools import combinations items = [‘a’, ‘b’, ‘c’, ‘d’] result = [] for combo in combinations(items, 2): result.append(combo) print(result) 1. [(‘a’, ‘b’), (‘a’, ‘c’), (‘a’, ‘d’), (‘b’, ‘c’), (‘b’, ‘d’), (‘c’, ‘d’)] 2. [(‘a’, ‘b’, ‘c’), (‘a’, ‘b’, ‘d’), (‘a’, ‘c’, ‘d’), (‘b’, ‘c’, ‘d’)] 3. [(‘a’, ‘b’), (‘a’, ‘c’), (‘b’, ‘c’)] 4. [(‘a’, ‘b’), (‘b’, ‘c’), (‘c’, ‘d’), (‘d’, ‘a’)] 133 / 134 下記のコードを実行した結果として正しいものを選択してください。 numbers = [2, 4, 6, 8, 10] for n in numbers: if n % 2 != 0: print(‘奇数が見つかりました。’) break else: print(‘奇数は見つかりませんでした。’) 1. 奇数は見つかりませんでした。 2. 奇数が見つかりました。 3. エラーが発生しました。 4. 何も表示されません。 134 / 134 下記のコードを実行した結果として正しいものを選択してください。 total = 0 for i in range(1, 10, 2): total += i print(total) 1. 25 2. 20 3. 30 4. 18 あなたのスコアは平均スコアは 0% 作成者 Wordpress Quiz plugin
Python技術試験 公式模試問題集
1 / 134
下記のコードを実行した結果として正しいものを選択してください。 name = ‘Alice’ age = 30 message = f'{name} is {age} years old.’
print(message)
2 / 134
下記のコードを実行した結果として正しいものを選択してください。 words = [‘banana’, ‘pie’, ‘Washington’, ‘book’] words.sort(key=lambda s: len(s)) print(words)
3 / 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)
4 / 134
下記のコードを実行した結果として正しいものを選択してください。 name = ‘Alice’ greeting = f”Hello, {name}!” print(greeting)
5 / 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)
6 / 134
下記のコードを実行した結果として正しいものを選択してください。 def greeting(name, greeting_phrase=’Hello’): return f'{greeting_phrase}, {name}!’
user_info = {‘name’: ‘Alice’, ‘greeting_phrase’: ‘Good morning’} result = greeting(**user_info)
print(result)
7 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [1, 2, 3, 4, 5] doubled = map(lambda x: x * 2, numbers) print(list(doubled))
8 / 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.’)
9 / 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)
10 / 134
下記のコードを実行した結果として正しいものを選択してください。 words = [‘banana’, ‘pie’, ‘Washington’, ‘book’] words.sort(key=lambda x: len(x)) print(words)
11 / 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)
12 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = {‘apple’: 2, ‘banana’: 4, ‘cherry’: 6} fruit_count = 0 for fruit in fruits.keys(): fruit_count += fruits[fruit]
print(fruit_count)
13 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [1, 2, 3, 4, 5] doubled_numbers = list(map(lambda x: x * 2, numbers)) print(doubled_numbers)
14 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits_count = {‘apples’: 2, ‘bananas’: 3, ‘cherries’: 5} for fruit in fruits_count.keys(): fruits_count[fruit] += 1
print(fruits_count)
15 / 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))
16 / 134
下記のコードを実行した結果として正しいものを選択してください。 words = [‘apple’, ‘banana’, ‘cherry’, ‘date’] word_lengths = {word: len(word) for word in words} print(word_lengths)
17 / 134
下記のコードを実行した結果として正しいものを選択してください。 words = [‘Hello’, ‘World’, ‘Python’, ‘Dictionary’] result = {word: len(word) for word in words if ‘o’ in word} print(result)
18 / 134
下記のコードを実行した結果として正しいものを選択してください。 def func(a, b, c): return a * b * c
values = {‘a’: 2, ‘b’: 3, ‘c’: 4} result = func(*values)
19 / 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)
20 / 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}’)
21 / 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)
22 / 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)
23 / 134
下記のコードを実行した結果として正しいものを選択してください。 names = [‘Alice’, ‘Bob’, ‘Charlie’] ages = [24, 50, 18] for name, age in zip(names, ages): print(f'{name} is {age} years old.’)
24 / 134
下記のコードを実行した結果として正しいものを選択してください。 def concat_strings(*args, sep=’/’): return sep.join(args)
result = concat_strings(‘apple’, ‘banana’, ‘cherry’, sep=’, ‘) print(result)
25 / 134
下記のコードを実行した結果として正しいものを選択してください。 def multiply(a, b=2): return a * b
result1 = multiply(3) result2 = multiply(3, 5) print(‘result1:’, result1, ‘result2:’, result2)
26 / 134
下記のコードを実行した結果として正しいものを選択してください。 def print_args(*args): for i, arg in enumerate(args): print(f’Argument {i}: {arg}’)
print_args(‘Python’, ‘is’, ‘fun’, ‘!’)
27 / 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)
28 / 134
下記のコードを実行した結果として正しいものを選択してください。 number = 123456.789 formatted_number = ‘{:,.2f}’.format(number) print(formatted_number)
29 / 134
下記のコードを実行した結果として正しいものを選択してください。 data = [‘Python’, ‘Java’, ‘C++’, ‘JavaScript’] result = len(data[2])
30 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = [‘apple’, ‘banana’, ‘cherry’] fruits.append(‘orange’) print(fruits)
31 / 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}’)
32 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [3, 5, 1, 4, 2] max_value = max(numbers) min_value = min(numbers) result = max_value + min_value print(result)
33 / 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)
34 / 134
下記のコードを実行した結果として正しいものを選択してください。 my_list = [‘apple’, ‘banana’, ‘cherry’] for item in reversed(my_list): print(item)
35 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [1, 2, 3, 4, 5] def square(x): return x * x
result = map(square, numbers) print(list(result))
36 / 134
下記のコードを実行した結果として正しいものを選択してください。 names = [‘Alice’, ‘Bob’, ‘Charlie’] ages = [24, 30, 28] for name, age in zip(names, ages): print(f'{name} is {age} years old.’)
37 / 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’))
38 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = iter([1, 2, 3]) output = [] while True: try: number = next(numbers) output.append(number) except StopIteration: break
print(output)
39 / 134
下記のコードを実行した結果として正しいものを選択してください。 from math import sqrt as s, factorial as f
result = f(5) / s(25) print(result)
40 / 134
下記のコードを実行した結果として正しいものを選択してください。 my_string = ‘Python Programming’ my_slice = slice(7, 18) result = my_string[my_slice] print(result)
41 / 134
下記のコードを実行した結果として正しいものを選択してください。 name = input(‘あなたの名前を教えてください: ‘) age = input(‘あなたの年齢を教えてください: ‘)
print(f’こんにちは、{name}さん!あなたは{age}歳ですね。’)
42 / 134
43 / 134
下記のコードを実行した結果として正しいものを選択してください。 iterable = [‘apple’, ‘banana’, ‘cherry’] iterator = iter(iterable)
first_item = next(iterator) second_item = next(iterator) third_item = next(iterator) forth_item = next(iterator)
44 / 134
下記のコードを実行した結果として正しいものを選択してください。 alphabet = ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’ my_slice = slice(5, 20, 3) result = alphabet[my_slice] print(result)
45 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5] numbers.sort() print(numbers)
46 / 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)
47 / 134
下記のコードを実行した結果として正しいものを選択してください。 name = input(‘あなたの名前を入力してください: ‘) print(‘こんにちは、’ + name + ‘さん!’)
48 / 134
下記のコードを実行した結果として正しいものを選択してください。 my_list = [‘apple’, ‘banana’, ‘cherry’, ‘date’]
result = len(my_list)
49 / 134
下記のコードを実行した結果として正しいものを選択してください。 number = 1024 formatted_string = ‘{:b}’.format(number) print(formatted_string)
50 / 134
下記のコードを実行した結果として正しいものを選択してください。 code = “def add(x, y): return x + y” exec(code) result = eval(‘add(2, 3)’) print(result)
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
下記のコードを実行した結果として正しいものを選択してください。 code = ‘result = [str(i) for i in range(5)]’ exec(code) print(eval(‘ “+”.join(result) ‘))
54 / 134
下記のコードを実行した結果として正しいものを選択してください。 my_list = [‘a’, ‘b’, ‘c’, ‘d’] reversed_list = list(reversed(my_list)) print(reversed_list)
55 / 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)
56 / 134
下記のコードを実行した結果として正しいものを選択してください。 values = [10, 20, 0, 30] print(all(value > 0 for value in values), any(value > 0 for value in values))
57 / 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())
58 / 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())
59 / 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)
60 / 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())
61 / 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)
62 / 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 = [①]
63 / 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())
64 / 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)
65 / 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())
66 / 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変数の内容を考慮したうえでの選択肢
67 / 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.’)
68 / 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)
69 / 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
70 / 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())
71 / 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() ①
72 / 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())
出力結果:
73 / 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())
74 / 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)
75 / 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()
76 / 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())
77 / 134
下記のコードを実行した結果として正しいものを選択してください。 my_dict = {‘apple’: 1, ‘banana’: 2, ‘cherry’: 3}
result = my_dict.get(‘banana’, ‘Not Found’) * my_dict.get(‘cherry’, ‘Not Found’)
78 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = {‘apple’: 3, ‘banana’: 1, ‘cherry’: 5} fruits[‘banana’] += 2 result = fruits.get(‘banana’) print(result)
79 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = [‘apple’, ‘banana’, ‘cherry’, ‘date’] fruits.pop(1) print(fruits)
80 / 134
下記のコードを実行した結果として正しいものを選択してください。 person = {‘name’: ‘Alice’, ‘age’: 25, ‘city’: ‘New York’} person[‘city’] = ‘Los Angeles’ print(person)
81 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = [‘apple’, ‘banana’, ‘cherry’, ‘date’] fruits[2] = ‘orange’ print(fruits)
82 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [2, 4, 6, 8, 10] reversed_numbers = numbers[::-1] print(reversed_numbers)
83 / 134
84 / 134
下記のコードを実行した結果として正しいものを選択してください。 person = {‘name’: ‘Alice’, ‘age’: 25, ‘job’: ‘Engineer’} person[‘age’] = 30 person[‘job’] = ‘Manager’ print(person)
85 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [2, 4, 6, 8, 10, 12, 14] result = numbers[-4:-1] print(result)
86 / 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’])
87 / 134
下記のコードを実行した結果として正しいものを選択してください。 tup = (10, 20, 30, 40, 50) tup = tup[:-2] + (60,) print(tup)
88 / 134
下記のコードを実行した結果として正しいものを選択してください。 tup = (10, 20, 30, 40) new_tup = tup[:2] + (50,) + tup[3:] print(new_tup)
89 / 134
下記のコードを実行した結果として正しいものを選択してください。 my_dict = {‘apple’: 1, ‘banana’: 2, ‘cherry’: 3} for key in my_dict.keys(): my_dict[key] *= 2
print(my_dict)
90 / 134
下記のコードを実行した結果として正しいものを選択してください。 my_list = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’] result = my_list[-4:-1] print(result)
91 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = {‘apple’: 10, ‘banana’: 5, ‘cherry’: 15}
for fruit in fruits: fruits[fruit] += 5
print(fruits[‘banana’])
92 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = [‘apple’, ‘banana’, ‘cherry’, ‘date’, ‘elderberry’, ‘fig’, ‘grape’] result = fruits[1:5]
93 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = {‘apple’: 100, ‘banana’: 200, ‘cherry’: 300} fruits[‘banana’] = 250 result = fruits[‘banana’] + fruits.get(‘orange’, 0) print(result)
94 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = [‘apple’, ‘banana’, ‘cherry’, ‘date’] fruits.pop(1) fruits.insert(1, ‘blueberry’) print(fruits)
95 / 134
下記のコードを実行した結果として正しいものを選択してください。 my_list = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’] print(my_list[2:5])
96 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = [‘apple’, ‘banana’, ‘cherry’, ‘date’] removed_item = fruits.pop(2) print(‘Removed:’, removed_item) print(‘Remaining fruits:’, fruits)
97 / 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)
98 / 134
下記のコードを実行した結果として正しいものを選択してください。 x = 10 def increment(): global x x += 1 increment() print(x)
99 / 134
下記のコードを実行した結果として正しいものを選択してください。 x = ‘7.5’ y = int(float(x)) print(y)
100 / 134
下記のコードを実行した結果として正しいものを選択してください。 x = ‘100’ y = 200 z = float(x) + y print(z)
101 / 134
102 / 134
下記のコードを実行した結果として正しいものを選択してください。 values = [0, ”, [], {}, set(), ‘False’, False, 1, -1]
count_true = 0 for v in values: count_true += bool(v)
print(count_true)
103 / 134
下記のコードを実行した結果として正しいものを選択してください。 number_str = ‘3.14’ number_float = float(number_str) number_int = int(number_float) print(number_int)
104 / 134
下記のコードを実行した結果として正しいものを選択してください。 a = 7 b = 3 a *= b print(a)
105 / 134
下記のコードを実行した結果として正しいものを選択してください。 number = 256 binary_str = bin(number) hex_str = hex(number)
print(‘Binary:’, binary_str, ‘Hexadecimal:’, hex_str)
106 / 134
下記のコードを実行した結果として正しいものを選択してください。 x = 7 y = 2 print(‘The result of 7 // 2 is:’, x // y)
107 / 134
下記のコードを実行した結果として正しいものを選択してください。 a = 10 b = 20 c = ’30’ d = a + b + int(c) print(d)
108 / 134
下記のコードを実行した結果として正しいものを選択してください。 a = 5 b = 10 a = b b = a + b print(a, b)
109 / 134
下記のコードを実行した結果として正しいものを選択してください。 a = 5 b = 10 c = b b = a a = c
print(‘a =’, a, ‘b =’, b)
110 / 134
下記のコードを実行した結果として正しいものを選択してください。 a = 8 b = 3 c = a ** b
print(c)
111 / 134
下記のコードを実行した結果として正しいものを選択してください。 x = 5 y = 3 print(f'{x} + {y} = {x + y}’)
112 / 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)
113 / 134
下記のコードを実行した結果として正しいものを選択してください。 number1 = 10 number2 = 20 result = number1 * number2 print(result)
114 / 134
下記のコードを実行した結果として正しいものを選択してください。 num_str = ‘7.25’ num_int = int(float(num_str)) print(num_int)
115 / 134
下記のコードを実行した結果として正しいものを選択してください。 a = 10 b = 5 c = ‘2’ d = a + b * int(c) print(d)
116 / 134
下記のコードを実行した結果として正しいものを選択してください。 x = 5 y = 2 print(x ** y)
117 / 134
下記のコードを実行した結果として正しいものを選択してください。 values = [0, ”, ‘Python’, [], {}, [1, 2, 3], {1: ‘one’}, None, False, True] results = [bool(value) for value in values] print(results)
118 / 134
下記のコードを実行した結果として正しいものを選択してください。 number = 7.25 print(int(number))
119 / 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)
120 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [2, 4, 6, 8, 10] for n in numbers: if n % 3 == 0: print(‘3の倍数が見つかりました。’) break else: print(‘3の倍数はありませんでした。’)
121 / 134
下記のコードを実行した結果として正しいものを選択してください。 names = [‘Alice’, ‘Bob’, ‘Charlie’] departments = [‘Engineering’, ‘Sales’, ‘Marketing’]
for name, department in zip(names, departments): print(f'{name} works in {department}’)
122 / 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))
123 / 134
下記のコードを実行した結果として正しいものを選択してください。 score = 75 result = ” if score >= 90: result = ‘Excellent’ elif score >= 80: result = ‘Good’ elif score >= 70: result = ‘Average’ else: result = ‘Poor’
124 / 134
下記のコードを実行した結果として正しいものを選択してください。 names = [‘Alice’, ‘Bob’, ‘Charlie’] ages = [24, 50, 18]
for name, age in zip(names, ages): print(f'{name} is {age} years old.’)
125 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = {‘apple’: 1, ‘banana’: 2, ‘cherry’: 3} result = ” for fruit, quantity in fruits.items(): result += f'{fruit}:{quantity} ‘
print(result.strip())
126 / 134
下記のコードを実行した結果として正しいものを選択してください。 n = 5 result = 1 while n > 0: result *= n n -= 1
127 / 134
下記のコードを実行した結果として正しいものを選択してください。 counter = 5 while counter > 0: print(‘Counter:’, counter) counter -= 1
128 / 134
下記のコードを実行した結果として正しいものを選択してください。 total = 0 for i in range(1, 11, 2): total += i
print(total)
129 / 134
下記のコードを実行した結果として正しいものを選択してください。 number = 25 if number % 2 == 0: result = ‘偶数です。’ else: result = ‘奇数です。’ print(result)
130 / 134
下記のコードを実行した結果として正しいものを選択してください。 fruits = {‘apple’: 2, ‘banana’: 5, ‘cherry’: 7} total = 0 for fruit, quantity in fruits.items(): total += quantity
131 / 134
下記のコードを実行した結果として正しいものを選択してください。 age = 20 if age >= 18: status = ‘adult’ else: status = ‘minor’
print(status)
132 / 134
items = [‘a’, ‘b’, ‘c’, ‘d’] result = [] for combo in combinations(items, 2): result.append(combo)
133 / 134
下記のコードを実行した結果として正しいものを選択してください。 numbers = [2, 4, 6, 8, 10] for n in numbers: if n % 2 != 0: print(‘奇数が見つかりました。’) break else: print(‘奇数は見つかりませんでした。’)
134 / 134
下記のコードを実行した結果として正しいものを選択してください。 total = 0 for i in range(1, 10, 2): total += i print(total)
あなたのスコアは
平均スコアは 0%