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

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

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

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

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

3. 
リストitems = ["apple", "banana", "cherry"]の要素をインデックス付きで出力するコードはどれでしょうか?

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

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

5. 
文字列text = "Python"の各文字を1文字ずつ出力するコードはどれでしょうか?

6. 
pipを使用してパッケージを最新バージョンに更新するための正しいコマンドはどれですか?

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

# ファイル名: sample.txt
# 初期内容:
# ---
# Line 1
# Line 2
# ---
with open('sample.txt', 'a') as f:
f.write("\nNew Line")
with open('sample.txt', 'r') as f:
print(f.read())

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

$ pip uninstall nonexistent

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

# ファイル名: sample.txt
# 初期内容: なし(ファイルは存在しない)
try:
with open('sample.txt', 'r+') as f:
f.write("Content")
except FileNotFoundError:
print("File not found")

10. 
次のコードについて、with文を使用しない場合に注意が必要な点を選んでください。

f = open('sample.txt', 'r')
content = f.read()
f.close()

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

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

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

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

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

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

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

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

16. 
次のコードで、文字列"apple"の各文字を逆順に出力するコードはどれでしょうか?

17. 
Pythonのパッケージリポジトリとして正しいものを選んでください。

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

$ pip install requests
$ python -c "import requests; print(requests.__version__)"

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

# ファイル名: 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())

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

$ python -c "import nonexistent"

21. 
open()関数における第2引数で指定するファイルモードとして正しい組み合わせを選んでください。

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

$ pip show requests

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

$ pip install requests
$ pip list | grep requests

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

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

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

26. 
次のコードで、ファイルのエンコーディングを指定する正しい方法を選んでください。

with open('sample.txt', 'w', ???) as f:
f.write("こんにちは")

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

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

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

numbers = [4, 1, 3, 2]
sorted_numbers = sorted(numbers)
print(numbers)
print(sorted_numbers)

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

# sample.txt の初期内容:
# ---
# Line 1
# Line 2
# ---
with open('sample.txt', 'r') as f:
for line in f:
print(line.strip())

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

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

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

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

text = "hello"
for i in range(len(text)):
if i % 2 == 0:
print(text[i])

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

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

34. 
Pythonで外部パッケージをインストールするために使用する標準的なツールとして正しいものを選んでください。

35. 
with文を使用する主な目的として正しいものを選んでください。

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

$ pip install requests
$ python -c "import requests; print(requests.get('https://httpbin.org/get').status_code)"

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

words = ["apple", "banana", "cherry"]
words.sort(key=len)
print(words)

38. 
次のコマンドについて、パッケージをアンインストールする正しい形式を選んでください。

39. 
特定のパッケージがインストールされているかを確認するコマンドはどれですか?

40. 
次のコードで、'x'モードを使用した場合の動作を選んでください。

with open('sample.txt', 'x') as f:
f.write("Exclusive content")

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