#!/bin/bash
echo -e "游戏开始" #输出游戏开始
count=3 #次数为3
ddd=$(($(($RANDOM%100)))) #生成随机数100以内
while true #循环
do
echo $ddd
read -p "请输入两位数字:" num
if [ $num -gt $ddd ] # 如果num 大于随机数
then
let count=$count-1 # 猜数次数减一
echo "猜大了,你还有 $count 次机会" #打印剩余次数
elif [ $num -lt $ddd ] #如果num小于随机数
then
echo "猜小了"
else
read -p "恭喜你,猜对了,是否继续玩游戏(yes/no) :" shuai
if [ $shuai == "yes" ] #判断输入的为yes或no
then
continue #为yes继续游戏
else
echo -e "欢迎下次光顾" #为no则退出
exit
fi
fi
if [ $count -eq 3 ] #如果次数用完将退出
then
exit
fi
done
shell脚本随机数
猜你喜欢
转载自blog.csdn.net/SKTONE_SHUAI/article/details/103738478
今日推荐
周排行