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-15

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

Prompt:

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

問題1 (関数のデフォルト引数)

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

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

print(greet())
  1. Hello, World!
  2. Hello, !
  3. Hello, None!
  4. Error
解説

正解:1. Hello, World! デフォルト引数 name は指定されていない場合 "World" が使われます。

問題2 (モジュールのインポート)

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

Python
import math
print(math.pi)
  1. 3
  2. 3.14
  3. 3.14159
  4. 3.141592653589793
解説

正解:4. 3.141592653589793 math モジュールの pi は円周率を表します。

問題3 (リストメソッド)

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

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

正解:1. [1, 2, 3, 4, 5] sort メソッドはリストを昇順に並び替えます。

問題4 (条件式)

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

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

正解:1. Even 条件式で x が偶数なら "Even" を返します。

問題5 (リストの組み込み関数)

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

Python
lst = [1, 2, 3, 4, 5]
print(sum(lst))
  1. 15
  2. 10
  3. 5
  4. Error
解説

正解:1. 15 sum 関数はリストの全要素の合計を返します。

問題6 (論理演算)

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

Python
print(True or False)
  1. True
  2. False
  3. None
  4. Error
解説

正解:1. True or 演算子は一方が真であれば真を返します。

問題7 (関数のスコープ)

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

Python
def outer():
    x = "outer"
    def inner():
        return x
    return inner()

print(outer())
  1. inner
  2. outer
  3. None
  4. Error
解説

正解:2. outer 内部関数 inner は外部関数 outer の変数 x にアクセスできます。

問題8 (セット操作)

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

Python
s = {1, 2, 3}
s.remove(2)
print(s)
  1. {1, 2, 3}
  2. {1, 3}
  3. {2, 3}
  4. Error
解説

正解:2. {1, 3} remove メソッドはセットから指定した要素を削除します。

問題9 (文字列フォーマット)

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

Python
name = "Alice"
age = 30
print(f"My name is {name} and I am {age} years old.")
  1. My name is and I am years old.
  2. My name is Alice and I am 30 years old.
  3. My name is {name} and I am {age} years old.
  4. Error
解説

正解:2. My name is Alice and I am 30 years old. f文字列を使用することで、変数を直接文字列に挿入できます。

問題10 (例外処理)

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

Python
lst = [1, 2, 3]
print(lst[5])
  1. IndexError
  2. ValueError
  3. TypeError
  4. KeyError
解説

正解:1. IndexError リストの範囲外にアクセスしようとすると IndexError が発生します。

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?