Above average · เกินค่าเฉลี่ย
Above average
Two loops, one after the other: the first works out the average, the second keeps the numbers above it.
This joins two patterns you have already used, the running total and the filter. Solving a problem in stages like this is how most longer programs are built.
สูงกว่าค่าเฉลี่ย
สองลูป, หนึ่งต่ออีกอัน: ตัวแรกคำนวณค่าเฉลี่ย, ตัวที่สองเก็บตัวเลขที่สูงกว่ามัน
นี่คือการรวมสองรูปแบบที่คุณเคยใช้แล้ว, ผลรวมสะสมและการกรอง. การแก้ปัญหาเป็นขั้นตอนเช่นนี้คือวิธีที่โปรแกรมยาวๆ ส่วนใหญ่ถูกสร้างขึ้น
Write above_average(nums) that returns a list of the numbers greater than the average of nums, in their original order. The list is never empty. · เขียน above_average(nums) ที่คืนค่ารายการของเลขที่มีค่า มากกว่า ค่าเฉลี่ยของ nums ตามลำดับเดิม รายการจะไม่ว่างเปล่า
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่