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

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

# ファイル名: sample.txt
# 初期内容:
# ---
# Data Science
# ---
with open('sample.txt', 'r+') as f:
f.seek(5)
f.truncate()
f.seek(0)
print(f.read())

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

words = ["one", "two", "three"]
for word in words:
print(word.upper())

3. 
リストnumbers = [3, 1, 4, 2]を昇順に並べ替えて出力するコードはどれでしょうか?

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

items = [(2, "b"), (3, "c"), (1, "a")]
sorted_items = sorted(items)
print(sorted_items)

5. 
辞書data = {"a": 3, "b": 1, "c": 2}のキーを昇順に並べ替えて出力するコードはどれでしょうか?

6. 
次のコードを実行した場合、エラーが発生する理由として正しいものを選んでください。

$ python -c "import nonexistent"

7. 
次のコマンドについて、特定のバージョンの外部パッケージをインストールするために正しい形式を選んでください。

8. 
次のコマンドについて、requirements.txtに基づいてパッケージをインストールするための正しい形式を選んでください。

9. 
次のコードで、ファイルを読み書きするために適切なモードを選んでください。

with open('sample.txt', ???) as f:
f.write("Content")
f.seek(0)
print(f.read())

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

# ファイル名: sample.txt
# 初期内容:
# ---
# Hello, World!
# ---
with open('sample.txt', 'w+') as f:
f.write("New Content")
f.seek(0)
print(f.read())

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

$ pip freeze > requirements.txt
$ cat requirements.txt

12. 
次のコードを実行した場合、requirements.txtファイルに保存される内容として正しいものを選んでください。

$ pip freeze > requirements.txt
$ cat requirements.txt

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

items = ["apple", "banana", "cherry"]
for i, item in enumerate(items):
print(i, item)

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

# ファイル名: sample.txt
# 初期内容:
# ---
# Initial
# ---
with open('sample.txt', 'r+') as f:
f.truncate(4)
print(f.read())

15. 
次のコマンドについて、特定のパッケージの詳細情報(例:バージョン、依存関係)を表示する正しい形式を選んでください。

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

# ファイル名: sample.txt
# 初期内容: なし(ファイルは存在しない)
with open('sample.txt', 'x') as f:
f.write("Exclusive Content")

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

# sample.txt の初期内容:
# ---
# Line 1
# Line 2
# ---
with open('sample.txt', 'r') as f:
content = f.read()
print(content)

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

# ファイル名: sample.txt
# 初期内容: なし
with open('sample.txt', 'wb') as f:
print(f.writable())

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

# ファイル名: sample.txt
# 初期内容:
# ---
# Line 1
# Line 2
# ---
with open('sample.txt', 'r+') as f:
f.seek(5)
f.write("Modified")
f.seek(0)
print(f.read())

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

# ファイル名: sample.txt
# 初期内容:
# ---
# Line 1
# Line 2
# ---
with open('sample.txt', 'r+') as f:
f.seek(7)
f.write("Modified")
f.seek(0)
print(f.read())

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

values = [10, 5, 20, 15]
values.sort(reverse=True)
print(values)

22. 
特定のパッケージの詳細情報(例:バージョン、依存関係、ホームページURL)を表示するためのコマンドはどれですか?

23. 
次のコードで、ファイルが存在しない場合に新規作成し、読み書きできるモードを選んでください。

with open('sample.txt', ???) as f:
f.write("New content")
f.seek(0)
print(f.read())

24. 
文字列text = "hello"の文字を昇順に並べ替えて出力するコードはどれでしょうか?

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

numbers = [1, 4, 3, 2]
numbers.sort()
numbers.reverse()
print(numbers)

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

$ pip uninstall nonexistent

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

total = 0
for i in range(1, 5):
total += i
print(total)

28. 
複数のパッケージを一括でインストールするためのコマンドはどれですか?

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

numbers = [1, 3, 2, 5, 4]
print(sorted(numbers)[::-1])

30. 
次のコードで、リストnames = ["Alice", "Bob", "Charlie"]を文字数の降順に並べ替えて出力するコードはどれでしょうか?

31. 
次のコードについて、with文が持つ特性として正しいものを選んでください。

with open('logfile.txt', 'a') as log:
log.write("Log entry\n")

32. 
Pythonでパッケージをインストール、管理するための標準的なコマンドラインツールはどれですか?

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

$ pip install numpy
$ python -c "import numpy as np; print(np.array([1, 2, 3]))"

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

numbers = [5, 10, 15]
for n in numbers:
print(n + 2)

35. 
次のコードで、with文を使うメリットとして正しいものを選んでください。

with open('sample.txt', 'r') as f:
content = f.read()

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

$ pip install requests==2.28.1
$ pip show requests

37. 
次のコマンドについて、すべてのインストール済みパッケージとそのバージョンを表示するために使用する正しい形式を選んでください。

38. 
すべてのインストール済みパッケージとそのバージョンを一覧表示するためのコマンドはどれですか?

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

# ファイル名: sample.txt
# 初期内容:
# ---
# Python is great!
# ---
with open('sample.txt', 'r+') as f:
f.seek(10)
f.write("amazing")
f.seek(0)
print(f.read())

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

data = [10, 5, 8]
print(sorted(data, reverse=True))
print(data)

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