0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Python3エンジニア認定基礎試験向けかもしれない問題集

Last updated at Posted at 2024-12-05

AIを使って問題を作成しています。

Prompt:

Python3エンジニア認定基礎試験に出てきそうな問題を作ってください。

問題1 (条件分岐)

次のコードの出力は何ですか?

Python
x = 7
if x % 2 == 0:
    print("Even")
else:
    print("Odd")
  1. Even
  2. Odd
  3. None
  4. Error
解説

正解:2. Odd x が奇数であるため、"Odd" が出力されます。

問題2 (辞書のメソッド)

次のコードの出力は何ですか?

Python
d = {'a': 1, 'b': 2}
d.update({'c': 3})
print(d)
  1. {'a': 1, 'b': 2}
  2. {'a': 1, 'b': 2, 'c': 3}
  3. {'a': 1, 'c': 3}
  4. {'c': 3, 'b': 2}
解説

正解:2. {'a': 1, 'b': 2, 'c': 3} update メソッドは辞書に新しいキーと値のペアを追加します。

問題3 (ループ)

次のコードの出力は何ですか?

Python
result = 1
for i in range(1, 4):
    result *= i
print(result)
  1. 1
  2. 6
  3. 10
  4. 24
解説

正解:2. 6 1 * 1 * 2 * 3 なので結果は 6 です。

問題4 (関数のネスト)

次のコードの出力は何ですか?

Python
def outer(a):
    def inner(b):
        return a + b
    return inner

add_five = outer(5)
print(add_five(3))
  1. 5
  2. 8
  3. 10
  4. 15
解説

正解:2. 8 内部関数 inner は外部関数 outer の引数 a を使用します。

問題5 (リスト操作)

次のコードの出力は何ですか?

Python
lst = [1, 2, 3, 4]
lst.pop()
print(lst)
  1. [1, 2, 3, 4]
  2. [2, 3, 4]
  3. [1, 2, 3]
  4. [1, 2, 3, 4, 5]
解説

正解:3. [1, 2, 3] pop メソッドはリストの最後の要素を削除します。

問題6 (クラスのメソッド)

次のコードの出力は何ですか?

Python
class MyClass:
    def __init__(self, value):
        self.value = value
    
    def double(self):
        return self.value * 2

obj = MyClass(5)
print(obj.double())
  1. 5
  2. 10
  3. 15
  4. 20
解説

正解:2. 10 double メソッドは value の2倍を返します。

問題7 (例外処理)

次のコードを実行した場合、どの例外が発生しますか?

Python
try:
    d = {'a': 1}
    print(d['b'])
except Exception as e:
    print(type(e))
  1. <class 'ValueError'>
  2. <class 'IndexError'>
  3. <class 'TypeError'>
  4. <class 'KeyError'>
解説

正解:4. <class 'KeyError'> 辞書に存在しないキーにアクセスしようとすると KeyError が発生します。

問題8 (文字列操作)

次のコードの出力は何ですか?

Python
s = "Python"
print(s[-1])
  1. P
  2. y
  3. n
  4. Error
解説

正解:3. n インデックス -1 は文字列の最後の要素を指します。

問題9 (標準入力)

次のコードの出力は何ですか? (標準入力として 3 を入力することを仮定します)

Python
n = int(input())
print(n * 2)
  1. 3
  2. 6
  3. 2
  4. Error
解説

正解:2. 6 標準入力から受け取った 3 を2倍します。

問題10 (リスト内包表記)

次のコードの出力は何ですか?

Python
lst = [x for x in range(5) if x % 2 == 0]
print(lst)
  1. [0, 2, 4]
  2. [1, 3, 5]
  3. [0, 1, 2, 3, 4]
  4. [2, 4, 6]
解説

正解:1. [0, 2, 4] リスト内包表記で、0から4の範囲内で偶数のみを含むリストを作成します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?