Home > Backend Development > PHP Problem > How to check student grade level using PHP if-else statement

How to check student grade level using PHP if-else statement

藏色散人
Release: 2023-03-12 07:02:02
Original
7326 people have browsed it

In a previous article "How to use PHP switch to display the day of the week", I introduced how to use the PHP switch statement to display the day of the week, in which Switch is one of the PHP conditional statements. Today we are going to introduce the use of another conditional statement~

The main content of this article is just as the title says. The specific problem description is "How to write a PHP program that uses if-else statements to check student performance based on scores"?

For example, if we divide students' grades into four grades: A, B, C, and unqualified, then we only need to judge the grade range based on the scores given!

Without further ado, let’s go directly to the code:

The PHP code is as follows:

<?php
$marks = 40;

if ($marks>=90)
{
    $grade = "甲等";
}
else if($marks>=75)
{
    $grade = "乙等";
}
else if($marks>=60)
{
    $grade = "丙等";
}
else
{
    $grade = "不合格";
}

echo "学生成绩: $grade";
Copy after login

Here we randomly gave a score of 40 , the judgment result is as follows:

学生成绩: 不合格
Copy after login

In the above code:

If the score is 90 or higher, the grade will be A; if the score is between 75 and 89, the grade will be B grade;

If the score is between 60 and 74, the grade is C grade; if the score is below 60, the student will fail.

Note:

if...else Statement: execute a block of code when the condition is true, and execute another block of code when the condition is not true;

The syntax is:

if (条件)
{
条件成立时执行的代码;
}
else
{
条件不成立时执行的代码;
}
Copy after login

Here is a brief introduction to everyone:

if...elseif....else Statement: in several To execute a block of code when one of the conditions is true, use the if....elseif...else statement.

its grammar

if (条件)
{
    if 条件成立时执行的代码;
}
elseif (条件)
{
    elseif 条件成立时执行的代码;
}
else
{
    条件不成立时执行的代码;
}
Copy after login

Finally, I would like to recommend the latest and most comprehensive "PHP Video Tutorial"~ Come and learn!

The above is the detailed content of How to check student grade level using PHP if-else statement. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template