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 วินาที

อยากฝึกโจทย์แบบนี้เพิ่มไหม เริ่มฝึกหัวข้อนี้ได้เลย ตรวจให้ทันทีทุกข้อ

เริ่มฝึกเลย