zoukankan      html  css  js  c++  java
  • 如来神掌第二式第六招----Shell游戏案例之猜数字

    ###############################################################################
    # Name : Mahavairocana                                                                                                                                           
    # Author : Mahavairocana                                                                                                                                         
    # QQ : 10353512                                                                                                                                                    
    # WeChat : shenlan-qianlan                                                                                                                                      
    # Blog : http://www.cnblogs.com/Mahavairocana/                                                                                                       
    # Description : You are welcome to reprint, or hyperlinks to indicate the                                                                        
    #                    source of the article, as well as author information.                                                                                ###############################################################################

    #!/bin/bash
    
    ####################################define color##########################
    red="33[31m"
    green="33[32m"
    yellow="33[33m"
    color="33[0m"
    check_number(){
    expr $num1 + 1 &>/dev/null
    if [ $? -ne 0 ];then
       echo -e "please input $red number $color"
       continue 1
    elif [ -z $num1 ];then
       echo -e "$yellow Can't be empty $color"
       continue 2
    elif [ $num1 -gt 59 ];then
       echo -e "$green Can't great than 59 $color"
       continue 3
    fi
    }
     
    
    guess_number(){
    if [ $num1 -gt $num ];then
       echo -e " $yellow too big $color"
    elif [ $num1 -eq $num ];then
       echo -e "$green congratulation, you  have guessed ! $color"
    elif [ $num1 -lt $num ];then
       echo -e "$green too small $color"
    fi
    }
     
    main(){
    while true
    do
    num=$(date +%S)
    read -p "please input number 1-59:" num1
     
    check_number
     
    guess_number
    done
    }
     
    main
  • 相关阅读:
    Windows下PHP开启mcrypt扩展和SSL(OpenSSL)扩展支持
    MyBatis 学习笔记
    试用百度云计算平台
    TCP三次握手及四次挥手详细图解
    Java开发中的23种设计模式详解
    Extjs4.1.0_从入门到精通
    SQLite3命令操作大全
    带你了解 HBase 数据模型和 HBase 架构
    让数据库无惧灾难,华为云GaussDB同城双集群高可用方案正式发布!
    论文阅读丨神经清洁: 神经网络中的后门攻击识别与缓解
  • 原文地址:https://www.cnblogs.com/Mahavairocana/p/8280740.html
Copyright © 2011-2022 走看看