แบบทดสอบ Python เรื่อง Loop 10 ข้อ

Quiz
•
Computers
•
9th Grade
•
Medium
อนุวัฒน์ เสียงหวาน
Used 11+ times
FREE Resource
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
ข้อใดเป็นการใช้ for loop ที่ถูกต้องใน Python
for(i=0; i<5; i++):
for i in range(5):
for i to 5:
foreach i in range(5):
Answer explanation
คำสั่ง 'for i in range(5):' เป็นการใช้ for loop ที่ถูกต้องใน Python ซึ่งจะทำให้ i มีค่าตั้งแต่ 0 ถึง 4 ในขณะที่ตัวเลือกอื่นๆ ไม่ถูกต้องตามไวยากรณ์ของ Python.
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
คำสั่งใดใช้หยุด while loop ได้ทันที
stop
halt
break
exit
Answer explanation
คำสั่ง 'break' ใช้เพื่อหยุดการทำงานของ while loop ทันที ในขณะที่คำสั่งอื่นๆ เช่น 'stop', 'halt', และ 'exit' ไม่ได้ถูกใช้ในบริบทนี้.
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
คำสั่ง continue ใน loop มีหน้าที่อะไร
หยุด loop ทันที
ข้ามไปยังรอบถัดไปของ loop โดยไม่รันโค้ดที่เหลือของรอบนั้น
ออกจาก loop และจบโปรแกรม
ทำให้ loop รันต่อไปแบบไม่มีที่สิ้นสุด
Answer explanation
คำสั่ง 'continue' ใน loop จะทำให้โปรแกรมข้ามไปยังรอบถัดไปโดยไม่รันโค้ดที่เหลือในรอบปัจจุบัน ซึ่งหมายความว่ามันจะไม่หยุด loop หรือออกจาก loop แต่จะเริ่มรอบใหม่ทันที.
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
คำสั่งใดสามารถใช้สร้าง loop ที่ไม่มีวันจบได้
while True:
for i in range(infinity):
for(; ;):
while(1 > 2):
Answer explanation
คำสั่ง 'while True:' สร้าง loop ที่ไม่มีวันจบเพราะเงื่อนไขใน while จะเป็นจริงตลอดเวลา ในขณะที่ตัวเลือกอื่นๆ จะมีเงื่อนไขที่ทำให้ loop จบได้ เช่น 'for i in range(infinity):' ไม่ถูกต้องเพราะ 'infinity' ไม่ใช่ค่าที่ถูกต้องใน Python.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
ข้อใดเป็น for loop ที่ใช้ range() เพื่อแสดงเลขคู่ระหว่าง 1 ถึง 10
for i in range(1, 10, 2): print(i)
for i in range(2, 11, 2): print(i)
for i in range(2, 10, 3): print(i)
for i in range(1, 11, 3): print(i)
Answer explanation
คำตอบที่ถูกต้องคือ 'for i in range(2, 11, 2): print(i)' เพราะใช้ range() เริ่มจาก 2 ถึง 10 โดยเพิ่มทีละ 2 ซึ่งจะแสดงเลขคู่ 2, 4, 6, 8, 10 ในช่วงที่กำหนด.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
ผลลัพธ์ของโค้ดต่อไปนี้คืออะไร?
แสดง "Hello" 3 ครั้ง
แสดง "Hello" 2 ครั้ง
แสดง "Hello" 4 ครั้ง
ไม่มีอะไรเกิดขึ้น
Answer explanation
โค้ดจะแสดง "Hello" 3 ครั้ง เนื่องจากมีการวนลูปที่ทำให้คำสั่งนี้ถูกเรียกใช้ 3 ครั้ง ดังนั้นผลลัพธ์ที่ถูกต้องคือ "แสดง 'Hello' 3 ครั้ง".
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
ข้อใดเป็นความแตกต่างระหว่าง while loop กับ for loop?
A) while loop ใช้เมื่อต้องการวนซ้ำเป็นจำนวนรอบที่แน่นอน
for loop ใช้เมื่อต้องการวนซ้ำตามเงื่อนไขที่กำหนด
while loop จะทำงานต่อเนื่องจนกว่าเงื่อนไขจะเป็นเท็จ ส่วน for loop ใช้กับตัววนซ้ำที่กำหนดช่วง
ไม่มีข้อแตกต่าง
Answer explanation
while loop จะทำงานต่อเนื่องจนกว่าเงื่อนไขจะเป็นเท็จ ซึ่งเหมาะสำหรับการวนซ้ำที่ไม่รู้จำนวนรอบแน่นอน ส่วน for loop ใช้เมื่อมีการกำหนดช่วงหรือจำนวนรอบที่แน่นอนในการวนซ้ำ.
Create a free account and access millions of resources
Similar Resources on Wayground
11 questions
สอบหลังเรียนการเก็บรวบรวมข้อมูลและการสำรวจข้อมูล

Quiz
•
9th - 12th Grade
15 questions
การออกแบบและการเขียนอัลกอริทึม

Quiz
•
1st - 10th Grade
10 questions
การดูแลรักษาและแก้ปัญหาคอมพิวเตอร์เบื้องต้น

Quiz
•
1st - 12th Grade
11 questions
แบบทดสอบ 10 ข้อ ใช้อันนี้

Quiz
•
9th - 12th Grade
10 questions
Kidbright

Quiz
•
1st - 12th Grade
10 questions
สอบย่อยบทที่ 2

Quiz
•
9th - 10th Grade
10 questions
ความหมายของเทคโนโลยี

Quiz
•
9th Grade
15 questions
กลางภาค ภาษาซี

Quiz
•
9th - 12th Grade
Popular Resources on Wayground
10 questions
Video Games

Quiz
•
6th - 12th Grade
20 questions
Brand Labels

Quiz
•
5th - 12th Grade
15 questions
Core 4 of Customer Service - Student Edition

Quiz
•
6th - 8th Grade
15 questions
What is Bullying?- Bullying Lesson Series 6-12

Lesson
•
11th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
22 questions
Adding Integers

Quiz
•
6th Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
Discover more resources for Computers
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
10 questions
Proper Keyboarding Techniques

Interactive video
•
6th - 10th Grade
14 questions
Inputs and Outputs: Computer Science Intro

Lesson
•
5th - 9th Grade
10 questions
Understanding Computers: Hardware, Software, and Operating Systems

Interactive video
•
7th - 12th Grade