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

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

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

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

$ python -c "import nonexistent"

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

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

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

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

5. 
次のコードについて、with文を使用して書き換えた正しい方法を選んでください。

f = open('sample.txt', 'w')
f.write("Hello, World!")
f.close()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

names = ["Alice", "Bob", "Charlie"]
for name in names:
if len(name) > 3:
print(name)

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

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

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

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

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

$ pip list | grep requests

26. 
次のコードで、0から3までの数字を使って「Index: X」を表示するコードはどれでしょうか?

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

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

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

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

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

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

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

$ pip install requests==2.28.1
$ pip show requests

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

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

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

text = "Python"
for char in text:
print(char, end="-")

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

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

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

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

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

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

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

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

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

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

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

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

people = [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}, {"name": "Charlie", "age": 35}]
sorted_people = sorted(people, key=lambda x: x["age"])
print([person["name"] for person in sorted_people])

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

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