首页 > 其他 > 详细

Guess the number

时间:2018-01-23 11:44:58      阅读:266      评论:0      收藏:0      [点我收藏+]
#! /bin/bash
total=0
num=$((RANDOM%41))
pear(){
read -p "please input number:" a
expr $a + 1 &> /dev/null
if [ $? -ne 0 ];then
echo "please input number;"
pear
fi
}

guess(){
((total++))
if [ $a -eq $num ];then
echo "you guess is rigth."
if [ $total -eq 3 ];then
echo "less than three times."
elif [ $total -gt 3 -a $total -lt 5 ];then
echo " less 5"
elif [ $total -eq 6 ];then
echo "it‘s many times."
fi
exit 0
elif [ $a -gt $num ];then
echo "$a is bigger than num"
pear
elif [ $a -lt $num ];then
echo "$a is less than num"
pear
fi
}

main(){
pear
while true;do
guess
done
}

Guess the number

原文:http://blog.51cto.com/546136/2064106

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!