标签:++ match 正确答案 strong 提醒 编程练习 输出 开始 read
#!/bin/bashpwd
function chakan()
{
echo " ___"
echo "| 请选择 |"
echo "|*1.下一轮考试 ****|"
echo "|*2.查看我的成绩单 *|"
echo "|***3.退 出 **|"
while true
do
read -p ‘请输入操作序号:‘ xz
case $xz in
[1])
sh $0
;;
[2])
cat $path/$id
;;
[3])
echo "感谢使用!"
break
;;
esac
done
}
function chengji()
{
if [ $sum -ge 90 ];then
echo "SMART"
echo "SMART">>$path/$id
elif [ $sum -ge 80 ] && [ $sum -lt 90 ];then
echo "GOOD"
echo "GOOD">>$path/$id
elif [ $sum -ge 70 ] && [ $sum -lt 80 ];then
echo "OK"
echo "OK">>$path/$id
elif [ $sum -ge 60 ] && [ $sum -lt 70 ];then
echo "PASS"
echo "PASS">>$path/$id
elif [ $sum -lt 60 ];then
echo "TRY AGAIN"
echo "TRY AGAIN">>$path/$id
fi
chakan $id
}
let sum=0
while true
do
read -p "请输入八位数字学号:" id
id=${id:=0}
if [ $id -gt 0 ] >>/dev/null;then
len=expr length $id
jilu=find $path -name $id
jilu=${jilu:=0}
fi
RET=expr match $id "[0-9][0-9]*$"
RET=${RET:=0}
if [ ${RET} -eq 8 ] && [ "$jilu" = "0" ] ; then
echo "您的学号是$id,开始考试!"
sleep 2
########################################
echo "考试记录单" >>$path/$id
echo "date -d "today" +%Y%m%d-%T
">>$path/$id
for((i=1;i<100;i++))
do
a[$i]=$i
done
########################################
while true
do
a=echo ${a[$RANDOM % ${#a[@]}]}
b=echo ${a[$RANDOM % ${#a[@]}]}
v=(1 2 3 4)br/>len=${#v[@]}
index=$(( RANDOM % len ))
c=echo ${v[$index]}
###加法
if [ $c -eq 1 ];then
let num=a+b
if [ $num -ge 0 ] && [ $num -le 99 ];then
let scount1=scount1+1
let scount5=scount1+scount2+scount3+scount4
echo ""
echo "">>$path/$id
echo "第$scount5题:"
echo "第$scount5题:">>$path/$id
echo "$a + $b = (?)"
echo "$a + $b = (?)">>$path/$id
while true
do
read -p ‘请输入答案:‘ as
let count=count+1
if [ "$num" == "$as" ];then
echo "你的回答是$as,回答正确!"
echo "你的回答是$as,回答正确!">>$path/$id
if [ $count -eq 1 ];then
let sum=sum+10
elif [ $count -eq 2 ];then
let sum=sum+7
elif [ $count -eq 3 ];then
let sum=sum+5
else
let sum=sum+0
fi
let count=0
break
else
echo "你的回答是$as,答案错误,请重新输入!"
echo "你的回答是$as,答案错误,请重新输入!">>$path/$id
if [ $count -ge 3 ];then
echo "回答错误超过三次,正确答案为$num"
echo "回答错误超过三次,正确答案为$num">>$path/$id
let count=0
break
fi
fi
done
if [ $scount5 -eq 10 ];then
echo "考试结束!"
echo "考试结束!">>$path/$id
echo
echo " ">>$path/$id
echo "你的成绩是$sum"
echo "你的成绩是$sum">>$path/$id
chengji $chengji
break
fi
fi
fi
##减法
if [ $c -eq 2 ];then
let num=a-b
if [ $num -ge 0 ] && [ $num -le 99 ];then
let scount2=scount2+1
let scount5=scount1+scount2+scount3+scount4
echo ""
echo "第$scount5题:"
echo "$a - $b = (?)"
echo "">>$path/$id
echo "第$scount5题:">>$path/$id
echo "$a - $b = (?)">>$path/$id
while true
do
read -p ‘请输入答案:‘ as
let count=count+1
if [ "$num" == "$as" ];then
echo "你的回答是$as,回答正确!"
echo "你的回答是$as,回答正确!">>$path/$id
if [ $count -eq 1 ];then
let sum=sum+10
elif [ $count -eq 2 ];then
let sum=sum+7
elif [ $count -eq 3 ];then
let sum=sum+5
else
let sum=sum+0
fi
let count=0
break
else
echo "你的回答是$as,答案错误,请重新输入!"
echo "你的回答是$as,答案错误,请重新输入!">>$path/$id
if [ $count -ge 3 ];then
echo "回答错误超过三次,正确答案为$num"
echo "回答错误超过三次,正确答案为$num">>$path/$id
let count=0
break
fi
fi
done
if [ $scount5 -eq 10 ];then
echo "考试结束!"
echo "考试结束!">>$path/$id
echo
echo " ">>$path/$id
echo "你的成绩是$sum"
echo "你的成绩是$sum">>$path/$id
chengji $chengji
break
fi
fi
fi
##乘法
if [ $c -eq 3 ];then
let num=a-b
if [ $num -ge 0 ] && [ $num -le 99 ];then
let scount3=scount3+1
let scount5=scount1+scount2+scount3+scount4
echo ""
echo "第$scount5题:"
echo "$a - $b = (?)"
echo "">>$path/$id
echo "第$scount5题:">>$path/$id
echo "$a - $b = (?)">>$path/$id
while true
do
read -p ‘请输入答案:‘ as
let count=count+1
if [ "$num" == "$as" ];then
echo "你的回答是$as,回答正确!"
echo "你的回答是$as,回答正确!">>$path/$id
if [ $count -eq 1 ];then
let sum=sum+10
elif [ $count -eq 2 ];then
let sum=sum+7
elif [ $count -eq 3 ];then
let sum=sum+5
else
let sum=sum+0
fi
let count=0
break
else
echo "你的回答是$as,答案错误,请重新输入!"
echo "你的回答是$as,答案错误,请重新输入!">>$path/$id
if [ $count -ge 3 ];then
echo "回答错误超过三次,正确答案为$num"
echo "回答错误超过三次,正确答案为$num">>$path/$id
let count=0
break
fi
fi
done
if [ $scount5 -eq 10 ];then
echo "考试结束!"
echo "考试结束!">>$path/$id
echo
echo " ">>$path/$id
echo "你的成绩是$sum"
echo "你的成绩是$sum">>$path/$id
chengji $chengji
break
fi
fi
fi
##除法
if [ $c -eq 4 ];then
let num=a/b
let ys=a%b
if [ $num -ge 0 ] && [ $num -le 99 ];then
let scount3=scount3+1
let scount5=scount1+scount2+scount3+scount4
echo ""
echo "第$scount5题:"
echo "$a ÷ $b = (?)"
echo "">>$path/$id
echo "第$scount5题:">>$path/$id
echo "$a ÷ $b = (?)">>$path/$id
while true
do
read -p ‘请输入答案:‘ as
if [ "$ys" != "0" ];then
read -p ‘请输入余数:‘ yushu
fi
let count=count+1
if [ "$num" == "$as" ] && [ "$ys" == "$yushu" ];then
echo "你的回答是$as,余数为$yushu,回答正确!"
echo "你的回答是$as,余数为$yushu,回答正确!">>$path/$id
if [ $count -eq 1 ];then
let sum=sum+10
elif [ $count -eq 2 ];then
let sum=sum+7
elif [ $count -eq 3 ];then
let sum=sum+5
else
let sum=sum+0
fi
let count=0
break
else
echo "你的回答是$as,余数为$yushu,答案错误,请重新输入!"
echo "你的回答是$as,余数为$yushu,答案错误,请重新输入!">>$path/$id
if [ $count -ge 3 ];then
echo "回答错误超过三次,正确答案为$num,余数为$ys"
echo "回答错误超过三次,正确答案为$num,余数为$ys">>$path/$id
let count=0
break
fi
fi
done
if [ $scount5 -eq 10 ];then
echo "考试结束!"
echo "考试结束!" >>$path/$id
echo
echo "" >>$path/$id
echo "你的成绩是$sum"
echo "你的成绩是$sum" >>$path/$id
chengji $chengji
break
fi
fi
fi
done
break
else
echo "输入非法或你已经参加过考试!"
fi
done
标签:++ match 正确答案 strong 提醒 编程练习 输出 开始 read
原文地址:http://blog.51cto.com/12240228/2158822