Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Shell to realize the game of guessing numbers

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to use Shell to guess numbers game". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

This article mainly introduces in detail the implementation of Shell number guessing game for everyone, the sample code in the article is very detailed, has a certain reference value, interested friends can refer to it.

This paper gives you an example to share the specific code of Shell to realize the number guessing game for your reference. The specific contents are as follows.

When you are new to Shell, you need to use shell to accomplish a variety of small goals, such as entering a date, calculating what day it is, or writing a Mini Game.

First of all, I would like to introduce a concept that is RANDOM,random (). The random function returns a random number between 0~num-1. Random (num) is a macro definition in stdlib.h, and both num and function return values are integers.

Here is the content of the script

#! / bin/bash # guess number game Init () {echo "# #" echo "echo" Guess Number Game "echo"echo" # # "} game () {number=$ [$RANDOM0] while: doread-p" enter the number you want to guess: "n1n2 = `echo $N1 | sed's / [0-9] / / g '`if [!-z $N2] then echo" you did not enter a number. " Continuefiif [$N1 = = $number] then echo "you guessed it." Read-p "do you want to play again? (yes/no)" an1 while true do case $an1 in yes) game break;; no) break;; *) exit esac done break elif [$N1-gt $number] then echo "big guess." Continue else echo "guessed small." Continue fidone} while truedoinitecho "1: Start Game" echo "0: exit" read-p "please input 0-1:" NUM case $NUM in1) game break;; 0) break;; esac done

This script is added to the simple number guessing game, and you can choose whether to do it again or not.

This is the end of the content of "how to use Shell to realize the number guessing game". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report