How to resolve the algorithm Guess the number/With feedback step by step in the Lasso programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Guess the number/With feedback step by step in the Lasso programming language
Table of Contents
Problem Statement
Write a game (computer program) that follows the following rules:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Guess the number/With feedback step by step in the Lasso programming language
Source code in the lasso programming language
#!/usr/bin/lasso9
local(
lower = integer_random(10, 1),
higher = integer_random(100, 20),
number = integer_random(#higher, #lower),
status = false,
guess
)
// prompt for a number
stdout('Guess a number: ')
while(not #status) => {
#guess = null
// the following bits wait until the terminal gives you back a line of input
while(not #guess or #guess -> size == 0) => {
#guess = file_stdin -> readSomeBytes(1024, 1000)
}
#guess = integer(#guess)
if(not (range(#guess, #lower, #higher) == #guess)) => {
stdout('Input not of correct type or range. Guess a number: ')
else(#guess > #number)
stdout('That was to high, try again! ')
else(#guess < #number)
stdout('That was to low, try again! ')
else(#guess == #number)
stdout('Well guessed!')
#status = true
}
}
You may also check:How to resolve the algorithm Walk a directory/Recursively step by step in the CoffeeScript programming language
You may also check:How to resolve the algorithm Integer comparison step by step in the Nanoquery programming language
You may also check:How to resolve the algorithm Lucky and even lucky numbers step by step in the Ring programming language
You may also check:How to resolve the algorithm Prime conspiracy step by step in the Julia programming language
You may also check:How to resolve the algorithm Ranking methods step by step in the Perl programming language