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. · לחץ על הרץ כדי לראות את התוצא כאן.