首頁  >  文章  >  後端開發  >  python、bash猜數字遊戲

python、bash猜數字遊戲

大家讲道理
大家讲道理原創
2016-11-09 11:38:181517瀏覽

#!/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\n" "<$USER>" "your record is $i! Try better next time! $DATE" |tee -a ./record.record
printf "\n\n"
printf "%15s %6s %-8s\n" "-----" "HISTORY RECORD" "-----"
cat ./record.record |sort -k5  -g|awk -F! &#39;{print $1,"!",$3}&#39;|head -10
printf "%15s %6s %-8s\n" "-----" "HISTORY RECORD" "-----"

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn