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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Guess the number step by step in the langur 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 langur programming language

Source code in the langur programming language

writeln "Guess a number from 1 to 10"

val .n = toString random 10
for {
    val .guess = read ">> ", RE/^0*(?:[1-9]|10)(?:\.0+)?$/, "bad data\n", 7, ""
    if .guess == "" {
        writeln "too much bad data"
        break
    }
    if .guess == .n {
        writeln "That's it."
        break
    }
    writeln "not it"
}

  

You may also check:How to resolve the algorithm Boolean values step by step in the Crystal programming language
You may also check:How to resolve the algorithm Image noise step by step in the Java programming language
You may also check:How to resolve the algorithm Memory allocation step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Multiplication tables step by step in the ALGOL W programming language
You may also check:How to resolve the algorithm Quine step by step in the PicoLisp programming language