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 秒完成。

想多做幾條同類題目?立即開始練習呢個課題,即做即批改。

立即練習