GUIDED LAB 04 OF 06 · VERIFIED SCARP
Average a vector
वेक्टर का औसत
The challenge · अभ्यास
Keep the four numeric values unchanged. Print their mean, 2.5, instead of their total.
चार संख्यात्मक मान न बदलें। उनके योग के बजाय औसत 2.5 प्रिंट करें।
starter.srp
// Lab: print the average instead of the sum.
bind numbers = [1.0, 2.0, 3.0, 4.0];
print(sum(numbers));
solution.stdout
2.5
Run and check your attempt locally
Copy starter.srp to attempt.srp in the same lab folder,
edit it, and use the pinned Scarp compiler from the repository root.
Keeping the same folder is important for imports and the bundled _support helper.
scarp verify labs/04-collections/attempt.srp
scarp exec labs/04-collections/attempt.srpCompare the printed output with the fixture shown above. No website execution, uploads or stored answers are involved.
Show hint · संकेत देखें
The published compiler provides a mean function for numeric vectors.
प्रकाशित कंपाइलर में संख्यात्मक वेक्टर के लिए mean फ़ंक्शन उपलब्ध है।
Reveal tested solution · सत्यापित हल देखें
// Compute the mean of four numeric vector elements.
bind numbers = [1.0, 2.0, 3.0, 4.0];
print(mean(numbers));
The numbers sum to 10.0; mean divides by four, producing 2.5.
संख्याओं का योग 10.0 है। mean उसे चार से भाग देकर 2.5 देता है।
Reference .srp on GitHub ↗The starter compiles but intentionally does not produce the goal. The reference solution and its output are verified on Linux, macOS and Windows against Scarp v0.0.6-alpha.3. Browse all labs ↗