linux基础命令利用日期生成随机数进行猜取

Implement "Guess Number Game" script program (see next page for the description)

Program will generate a secret number, and ask player to guess. It will tell player if his/her guess is too big or too small. It will exit when any of these two cases happen:

1. Player guessed the secret number correctly. Print "Congratulations!"

2. Timed out. Player did not guess quickly enough. Print "Timed out!"

Requirement:

1. Use command 'date' to get current time, and use 'cut' to retrieve the second as the secret number.  Hint, delimitor is ':' for 'cut' command

2. Use TMOUT to set timeout to 5 seconds

3. Allow user to press ENTER without any number. In this case, print "You did not guess a number". Loop back to wait for player's next try

4. Assume player only enter number

 

翻译:

程序将产生一个神秘数字,并且要求玩家去猜它。他将告诉玩家他的数字是大是小,程序将将遇见两种情况退出:

1,玩家猜到神秘数字并且打印congratulations!

2,时间结束,玩家没足够快的猜出数字,打印Timed out!

需求:使用date命令获得当前时间,并且用cut指令去获得date的秒部分当做神秘数字,提示:分隔符是冒号(:)。使用TMOUT 去设定时间限制是5秒。允许用户去按ENTER并且不输入任何数,在这种情况,打印:You did not guess a number.

然后用循环去返回去等待玩家下一次猜数。假设,玩家只输数字

1.代码

 

2.执行结果

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值