a) Write a PHP script to identify a student grade. Your script must use switch keyword, comparative and logical operators.
b) Write the script output that print the grade (i.e., A or B) based on the marks (e.g., $mark =80).
Marks Grade
90-100 A
80-89 B
70-79 C
60-69 D
Less than 60 F
a) Here is a PHP script that uses a switch statement, comparative operators, and logical operators to determine a student’s grade based on their marks:
<?php
// Set the marks
$marks = 80;
// Use a switch statement to determine the grade
switch(true) {
case ($marks >= 90):
$grade = ‘A’;
break;
case ($marks >= 80):
$grade = ‘B’;
break;
case ($marks >= 70):
$grade = ‘C’;
break;
case ($marks >= 60):
$grade = ‘D’;
break;
default:
$grade = ‘F’;
}
// Print the grade
echo “The grade is: $grade\n”;
?>
b) Here is the output of the script when $marks is set to 80:
The grade is: B