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

想多做几道同类题目?立即开始练习这个课题,边做边批改。

立即练习