gpt4 book ai didi

php - 得分范围 PHP

转载 作者:太空宇宙 更新时间:2023-11-04 14:14:27 25 4
gpt4 key购买 nike

我正在尝试创建一个在我的 if 语句中返回特定代码的程序。

分数低于70:在h1标签中显示分数,在h2标签中显示其等级:D

分数在70-80之间:在h1标签中显示分数,在h2标签中显示他们的成绩:C

分数在80-90之间:在h1标签中显示分数,在h2标签中显示其等级:B;

如果有人得了 80,给他们打 B90-100之间的分数:在h1标签中显示分数,在h2标签中显示他们的等级:A;

如果有人得了 90,给他们一个 A例如,您的代码输出如下所示:

这是我的代码:

function random(){
$number = rand(50,100);
echo "<h1> Your Score: {$number}/100 </h1>";

if($number>70){
echo "<h2>Your Grade is D</h2>";
}else if($number=(range(70, 80))){
echo "<h2>Your Grade is C</h2>";
}else if($number=(range(80, 90))){
echo "<h2>Your Grade is B</h2>";
}else if($number==80){
echo "<h2>Your Grade is B</h2>";
}else if($number=(range(90, 100))){
echo "<h2>Your Grade is A</h2>";
}


}

$score = random();
echo $score;

目前它没有显示正确的成绩和文本。有什么想法吗?

最佳答案

目前你的逻辑有点不对。

数字应该从最大开始向下,否则它会达到 > 70 并且它会立即适合该括号。

<?php
function random(){
$number = rand(50,100);
echo "<h1> Your Score: {$number}/100 </h1>";

if($number >= 90){
echo "<h2>Your Grade is A</h2>";
}else if($number >= 80){
echo "<h2>Your Grade is B</h2>";
}else if($number >= 70){
echo "<h2>Your Grade is C</h2>";
}else if($number < 70){
echo "<h2>Your Grade is D</h2>";
}


}

$score = random();
echo $score;
?>

关于php - 得分范围 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31181372/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com