python、bash猜数字游戏
来源:动视网
责编:小采
时间:2020-11-27 14:27:55
python、bash猜数字游戏
python、bash猜数字游戏:#!/bin/bash NUM=`echo $RANDOM$RANDOM |cut -c 2-3` DATE=`date +%y%m%d-%H:%M` read -p Please input your name: USER i=1 while true do read -p Please input a double-digit: input case $input in [0-9][0-9] ) if [ $input -gt $NUM ] ;then e
导读python、bash猜数字游戏:#!/bin/bash NUM=`echo $RANDOM$RANDOM |cut -c 2-3` DATE=`date +%y%m%d-%H:%M` read -p Please input your name: USER i=1 while true do read -p Please input a double-digit: input case $input in [0-9][0-9] ) if [ $input -gt $NUM ] ;then e

#!/bin/bash
NUM=`echo $RANDOM$RANDOM |cut -c 2-3`
DATE=`date +%y%m%d-%H:%M`
read -p "Please input your name: " USER
i=1
while true
do
read -p "Please input a "double-digit": " input
case $input in
[0-9][0-9] )
if [ $input -gt $NUM ] ;then
echo "Try smaller!"
elif [ $input -lt $NUM ];then
echo "Try bigger!"
else
echo "Good! You are right!"
break;
fi ;;
*)
echo "The number should be in 1 to 100: " ;;
esac
i=$((i+1))
done
printf "%-12s %s
" "<$USER>" "your record is $i! Try better next time! $DATE" |tee -a ./record.record
printf "
"
printf "%15s %6s %-8s
" "-----" "HISTORY RECORD" "-----"
cat ./record.record |sort -k5 -g|awk -F! '{print $1,"!",$3}'|head -10
printf "%15s %6s %-8s
" "-----" "HISTORY RECORD" "-----"
python、bash猜数字游戏
python、bash猜数字游戏:#!/bin/bash NUM=`echo $RANDOM$RANDOM |cut -c 2-3` DATE=`date +%y%m%d-%H:%M` read -p Please input your name: USER i=1 while true do read -p Please input a double-digit: input case $input in [0-9][0-9] ) if [ $input -gt $NUM ] ;then e