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.执行结果