要求
1.判断提交的数据保证数字 2.计算平均的成绩average,按照成绩分为,A,B,C,D,E
php代码部分
<?php
$c=$_POST['yuwen'];
$m=$_POST['shuxue'];
if(is_numeric($c & $m)){
$average = ($c + $m)/2;
if($average >= 90){
echo "A";}
elseif($average >= 80){
echo "B";}
elseif($average >= 70){
echo "C";}
elseif($average >= 60){
echo "D";}
else{
echo "E";}
}
else{
echo "请输入整数";
}
?>
表单部分
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>平均成绩</title>
</head>
<body>
<style>
form{
border:1px solid black;
</style>
<form action='averge.php' method='post'>
<center>
语文: <input type='text' name='yuwen'><br/>
<br/>
数学: <input type='text' name='shuxue'><br/>
<br/>
<input type='submit' value='submit'>
<center/>
</form>
</body>
</html>
运行结果
|