Question

In: Computer Science

Linux: I have a working script but need a high/low comparison added to each guess by...

Linux: I have a working script but need a high/low comparison added to each guess by the user.

choice=$(( $RANDOM % 100 + 1 ))

read -p 'Please choose a number from 1-100:' variable

while [ $variable -ne $choice ];
do
echo "Your choice was wrong. Please try again."
read -p 'Please choose a number from 1-100:' variable
done

echo "You chose correctly!!!"

The comparison is the variable chosen by the game is supposed to be guessed by the user. Because the choices range from 1-100, I need the script to tell the user if they chose too high or too low until the user makes the correct choice.

Solutions

Expert Solution

Code:

choice=$(( $RANDOM % 100 + 1 ))

variable=0

while [ $variable -ne $choice ];

do

read -p 'Please choose a number from 1-100:' variable

# if variable is greater than choice

if [ $variable -gt $choice ]

then

echo "Your choice is too high. Please try again"

# if variable is less than choice

elif [ $variable -lt $choice ]

then

echo "Your choice is too low. Please try again"

# if variable equals choice

else

echo "You chose correctly!!!"

fi

done

Code Screenshot:

Sample Output:


Related Solutions

Linux Have your script request a word from the user, then checks if it is an...
Linux Have your script request a word from the user, then checks if it is an ordinary file. If yes display the size of the file. If the name is a directory, then display the number of objects in that directory, then display the second line of a long listing of that directory.
I need an Arduino uno code to measure high low levels with hcsr04 of a tank...
I need an Arduino uno code to measure high low levels with hcsr04 of a tank and display it on i2c 20x4 lcd.
Design two shell programs working on Linux (Ubuntu) Design a shell script program, 1) reading given...
Design two shell programs working on Linux (Ubuntu) Design a shell script program, 1) reading given only two integer numbers from command line arguments and computing their multiplication. If two integer numbers are not given, print “Wrong Input” on your screen. Note that, the number of arguments is known when the script runs. Take a screenshot showing your shell program and its execution step. Design a shell program to remove all the shell programming files ending with sh on your...
I am attempting to write a script using bash on Linux. My program must save the...
I am attempting to write a script using bash on Linux. My program must save the long list format of the parent directory to a text file. Then, it must print how many items are in this parent directory. Then, it must sort the file in reverse order and save it to a different text file. I understand that the parent directory is accessed using cd .., and I understand that a file can be written to by echoing and...
.How do you rank (high or low) the diversity issues in comparison to the other ethical...
.How do you rank (high or low) the diversity issues in comparison to the other ethical issues in your organization?
I need to implement a code in python to guess a random number. The number must...
I need to implement a code in python to guess a random number. The number must be an integer between 1 and 50 inclusive, using the module random function randint. The user will have four options to guess the number. For each one of the failed attempts, the program it should let the user know whether is with a lower or higher number and how many tries they have left. If the user guess the number, the program must congratulate...
I would guess that each of you have been to a fast-food restaurant. Think about all...
I would guess that each of you have been to a fast-food restaurant. Think about all of the aspects of the operation procedures used to take, process, and fill an order and deliver the order to the customer. Based on what you have observed during your visit to one of these restaurants, identify at least three variable and three fixed costs. Can you identify any potential mixed costs? Why is the restaurant willing to sell a large drink for only...
In international business, discuss how Hall’s concept of high and low context comparison of cultures impacts...
In international business, discuss how Hall’s concept of high and low context comparison of cultures impacts businesses in different country settings. Compare any four dimensions, thus identifying how each would manifest (i.e., visually or verbally, as in negotiations) itself in a business situation.
what is the junction low (i need traffic flow not current), plees i also need a...
what is the junction low (i need traffic flow not current), plees i also need a reference . thank you
Revision Question 1 on Linux. Please briefly explain the shell script given. a) You have just...
Revision Question 1 on Linux. Please briefly explain the shell script given. a) You have just logged in and have a directory called "images" in your home directory containing the following files: favicons login.png logo.png newlogo.png where "favicons is a directory and contains the files favicon.ico favicon.gif favicon.png favicon.jpg Describe the results you would expect when executing the following shell commands: i) ls images/*og* | wc -1 ii) ls -ld images/* iii) rmdir images/favicons iv) cp images/*/*png images v) rm...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT