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

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

2. 
pipでパッケージをインストールする際に、その依存関係に問題がある場合に使用するコマンドはどれですか?

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

$ pip install requests==2.28.1
$ pip show requests

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

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

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

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

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

numbers = [1, 2, 3]
for i in range(len(numbers)):
numbers[i] *= 2
print(numbers)

7. 
リストnumbersの要素を順番に出力するコードはどれでしょうか?

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

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

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

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

10. 
次のコードで、リストvalues = [10, 30, 20, 40]を降順に並べ替えて出力するコードはどれでしょうか?

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

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

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

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

13. 
次のコードで、リストitems = [("apple", 3), ("banana", 2), ("cherry", 5)]を数値の昇順で並べ替えて出力するコードはどれでしょうか?

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

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

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

$ pip install requests
$ pip list | grep requests

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

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

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

$ pip list | grep requests

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

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

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

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

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

data = [0, "", False, None]
for value in data:
if value:
print("True value")
else:
print("False value")

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

mixed = ["10", "2", "30", "22"]
print(sorted(mixed, key=int))

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

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

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

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

$ pip install numpy
$ python -c "import numpy as np; print(np.zeros((2, 2)))"

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

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

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

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

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

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

$ pip show requests

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

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

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

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

31. 
0から10までの偶数を出力するコードはどれでしょうか?

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

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

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

$ pip uninstall nonexistent

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

35. 
次のコードで使用されているファイルモードに対応する操作を選んでください。

with open('sample.txt', 'a') as f:
f.write("Appended content")

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

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

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

# ファイル名: sample.txt
# 初期内容:
# ---
# Line1
# Line2
# ---
with open('sample.txt', 'a+') as f:
f.write("\nNew Line")
f.seek(0)
print(f.read())

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

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

fruits = ["banana", "apple", "cherry"]
print(sorted(fruits, key=lambda x: x[-1]))

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

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

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