程序运行截图如下:
源码如下:
- <?php
- $name = "小明";
- $score = 88;
-
- if(is_int($score) || is_float($score)){
-
- if($score == 100){
-
- $str = "S级";
- }
- else if($score >= 90 && $score < 100){
-
- $str = "A级";
- }
- else if($score >= 80 && $score < 90){
-
- $str = "B级";
- }
- else if($score >=70 && $score < 80){
-
- $str = "C级";
- }
- else if($score >=60 && $score < 70){
-
- $str = "D级";
- }
- else if($score >= 0 && $score < 60){
-
- $str = "E级";
- }
- else{
-
- $str = "请输入0~100的数据";
- }
- }
- else{
-
- $str = "输入的数值格式不对";
- }
- ?>
-
- <h2>学生成绩等级</h2>
- <p>学生姓名: <?php echo $name ?></p>
- <p>学生成绩: <?php echo $score ?></p>
- <p>学生等级: <?php echo $str ?></p>