Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php // 定义两个变量,保存学生姓名和分数 $studentName = '小明'; $score = 85; // 判断分数是否为合格的分数值 if (!is_numeric($score) || $score < 0 || $score > 100) { $grade = '成绩输入不合法,请输入0到100之间的数值'; } else { // 使用if...else条件判断语句判断成绩等级 if ($score >= 90 && $score <= 100) { $grade = 'A级'; } elseif ($score >= 80 && $score <= 89) { $grade = 'B级'; } elseif ($score >= 70 && $score <= 79) { $grade = 'C级'; } elseif ($score >= 60 && $score <= 69) { $grade = 'D级'; } else { $grade = 'E级'; } } // 以友好格式显示学生姓名、成绩和等级判断结果 printf("学生姓名:%s\n学生分数:%d分\n成绩等级:%s", $studentName, $score, $grade);
Copy Clear