Task 2(a): Number Sequence, Sum and Average
0) {
$numList = [];
$totalSum = 0;
for ($index = 1; $index <= $userValue; $index++) {
$numList[] = $index;
$totalSum += $index;
}
$avgValue = $totalSum / $userValue;
echo '
' . implode(', ', $numList) . " ({$userValue} numbers)
";
echo '
' . $totalSum . " (sum of {$userValue} numbers)
";
echo '
' . round($avgValue, 2) . " (average of {$userValue} numbers)
";
} else {
echo '
Please provide a positive integer.
';
}
}
?>
Task 2(b): Final Mark Calculation
35, 'year' => 50],
['exam' => 42, 'year' => 55],
['exam' => 58, 'year' => 62]
];
echo '
';
echo 'Exam | Year | Final Score |
';
foreach ($marksArray as $entry) {
$finalScore = computeFinalScore($entry['exam'], $entry['year']);
echo "{$entry['exam']} | {$entry['year']} | {$finalScore} |
";
}
echo '
';
?>
Task 2(c): SADC Countries and Capitals
The capital of {$chosenCountry} is {$sadcCountries[$chosenCountry]}.";
} else {
echo "
Please select a valid country from the list.
";
}
}
?>