GCE O-Level · Computing (7155)

Python Code:練習問題

その場で採点される選択問題 5 問と、解説つきの記述問題 2 問。すべて「Python Code」からの出題です。

7 問14 無料・登録不要
問 1
1

In Python, which of the following is the correct code to open a file named "results.txt" for the purpose of adding new data to the end of the existing content without overwriting it?

問 2
1

A programmer wants to generate a random integer between 1 and 10 (inclusive). Which Python command should be used after importing the random module?

問 3
1

What is the output of the following Python code?

data = [2, 4, 6]
result = 0
for i in range(len(data)):
    result += data[i] * i
print(result)

問 4
1

Which of the following is the correct Python expression to calculate the remainder when 25 is divided by 4?

問 5
1

What is the output of the following Python code segment?

x = 17
y = 5
print(x // y, x % y)

問 6
4

A student wrote a Python script to calculate the average score of a class. The script asks for the number of students, then prompts for each student's score one by one.

(a) Write a Python code snippet using a for loop to input 5 student scores and store them in a list named scores.
(b) Explain the difference between using a for loop and a while loop in this context.

まず自分で答えを書いてから、解説と照らし合わせましょう。

問 7
5

Consider a scenario where you need to validate user passwords. A valid password must be at least 8 characters long and must not contain any spaces.

(a) Define a function validate_password(pw) that takes a string as a parameter. It should return True if the password meets both criteria and False otherwise.
(b) Inside the function, use len() and the not in operator or a string method to perform the checks.
(c) Demonstrate how to call this function with an input string provided by the user.

まず自分で答えを書いてから、解説と照らし合わせましょう。

※ thinkaのコンテンツはAIにより生成されているため、内容が正確でない場合があります。補助教材としてご使用いただき、公式の教材と合わせてご確認ください。

模範解答は見ました。次はあなたの答案を採点します。

このページは良い答案の形を示せますが、あなたの答案に何が足りないかは教えられません。thinka は実際の採点基準に沿って記述答案を約 15 秒で採点します。

同じような問題をもっと解きたい?このトピックの新しい問題を、解きながら採点。

練習を始める