How to resolve the algorithm Guess the number step by step in the Lasso programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Guess the number step by step in the Lasso programming language

Table of Contents

Problem Statement

Write a program where the program chooses a number between   1   and   10. A player is then prompted to enter a guess.   If the player guesses wrong,   then the prompt appears again until the guess is correct. When the player has made a successful guess the computer will issue a   "Well guessed!"   message,   and the program exits. A   conditional loop   may be used to repeat the guessing until the user is correct.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Guess the number step by step in the Lasso programming language

Source code in the lasso programming language

local(
	number	= integer_random(10, 1),
	status	= false,
	guess
)

// prompt for a number
stdout('Guess a number between 1 and 10: ')

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, 1, 10) == #guess)) => {
		stdout('Input not of correct type or range. Guess a number between 1 and 10: ')
	else(#guess == #number)
		stdout('Well guessed!')
		#status = true
	else
		stdout('You guessed wrong number. Guess a number between 1 and 10: ')
	}

}




local(
	number	= integer(web_request -> param('number') or integer_random(10, 1)),
	status	= false,
	guess	= web_request -> param('guess'),
	_guess	= integer(#guess),
	message	= 'Guess a number between 1 and 10'
)



if(#guess) => {
	if(not (range(#_guess, 1, 10) == #_guess)) => {
		#Message = 'Input not of correct type or range. Guess a number between 1 and 10'
	else(#_guess == #number)
		#Message = 'Well guessed!'
		#status = true
	else
		#Message = 'You guessed wrong number. Guess a number between 1 and 10'
	}
}


?>

	
		Guess the number - Rosetta Code
	
	
		

[#message]

[if(not #status)]

[/if]

You may also check:How to resolve the algorithm User input/Text step by step in the Raku programming language
You may also check:How to resolve the algorithm Price fraction step by step in the Scala programming language
You may also check:How to resolve the algorithm Chaos game step by step in the Yabasic programming language
You may also check:How to resolve the algorithm Sum digits of an integer step by step in the Lasso programming language
You may also check:How to resolve the algorithm Unicode strings step by step in the Sidef programming language