ROUND, RANDOM and a trace · ROUND, RANDOM و جدول التتبع
A shop rounds a price
ROUND(Value, Places)returnsValuerounded toPlacesdecimal places.Placesis an integer.ROUND(3.14159, 2)is3.14.ROUND(9.6, 0)is the whole number10.- The syllabus lists
ROUNDwithDIV,MODandRANDOM.
متجر يقرب السعر
ROUND(Value, Places)يُرجعValueمقرباً إلىPlacesمنازل عشرية.Placesعدد صحيح.ROUND(3.14159, 2)هو3.14.ROUND(9.6, 0)هو العدد الصحيح10.- المنهج يذكر
ROUNDمعDIV،MODوRANDOM.
OUTPUT ROUND(3.14159, 2)
OUTPUT ROUND(9.6, 0)
A dice uses RANDOM
RANDOM()returns a real from 0 to 1, including both ends. Each run can differ.- A board-game dice is
ROUND(RANDOM() * 6, 0). The paper uses it when the result may vary, so you are not asked for one fixed output.
نرداء يستخدم RANDOM
RANDOM()يُرجع عدداً حقيقياً من 0 إلى 1، شاملاً الطرفين. قد differs كل تشغيل.- رداء لعبة لوحية هو
ROUND(RANDOM() * 6, 0). الورقة تستخدمه عندما قد يختلف النتيجة، حتى لا يُطلب منك إخراج ثابت واحد.
OUTPUT ROUND(RANDOM() * 6, 0)
Fill a trace table
- A trace table is a dry run. One row is one pass of the loop. You write the variables after that pass.
Totalstarts at 0. AfterI = 1it is 1. AfterI = 2it is 3. AfterI = 3it is 6.
| I | Total |
|---|---|
| 1 | 1 |
| 2 | 3 |
| 3 | 6 |
املأ جدول التتبع
- جدول التتبع هو تشغيل جاف. الصف الواحد هو دورة واحدة من الحلقة. تكتب المتغيرات بعد تلك الدورة.
Totalيبدأ بـ 0. بعدI = 1هو 1. بعدI = 2هو 3. بعدI = 3هو 6.
| I | المجموع |
|---|---|
| 1 | 1 |
| 2 | 3 |
| 3 | 6 |
One row per pass · صف واحد لكل دورة
A trace table records each variable after that pass of the loop. Here Total is the running sum of I. · يسجل جدول التتبع كل متغير بعد كل دورة من حلقة التكرار هذه. هنا Total هو المجموع المتراكم لـ I.
DECLARE I, Total : INTEGER
Total ← 0
FOR I ← 1 TO 3
Total ← Total + I
OUTPUT I, " ", Total
NEXT I
Watch out
- Round a half only when you have checked the digit. The tasks here are not on a halfway value.
RANDOM()is notRAND.RANDbelongs to the 9618 guide, not to this syllabus.
انتبه
- قرب النصف فقط عندما تتحقق من الرقم. المهام هنا ليست على قيمة منتصف الطريق.
RANDOM()ليسRAND.RANDينتمي إلى دليل 9618، وليس到这个 المنهج.
Common mistakes
ROUNDtakes the value first and the number of places second.- In a trace, record the values after the line has run, not the values you hope the next line will produce.
أخطاء شائعة
ROUNDيأخذ القيمة أولاً وعدد المنازل ثانياً.- في التتبع، سجّل القيم بعد أن تم تنفيذ السطر، وليس القيم التي تتأملها السطر التالي أن تنتج.
Now you try
- The first task is
ROUND. The second prints a trace, one row per line. - Press Check answer to test it.
الآن جرب بنفسك
- المهمة الأولى هي
ROUND. الثانية تطبع تتبعاً، صف واحد لكل سطر. - اضغط على تحقق من الإجابة لاختبارها.
Output ROUND(3.14159, 2) and ROUND(9.6, 0), each on its own line. · أخرج ROUND(3.14159, 2) و ROUND(9.6, 0)، كل واحد في سطر خاص به.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.
Start Total at 0. For I from 1 to 3, add I to Total and output I, a space, and Total on that line. The three lines are the trace. · ابدأ Total من 0. لكل I من 1 إلى 3، أضف I إلى Total وأخرج I، مسافة، وTotal في نفس السطر. الأسطر الثلاثة تمثل المسار.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.