How to resolve the algorithm Guess the number/With feedback step by step in the Logo 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 Logo 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 Logo programming language
Source code in the logo programming language
to guess [:max 100]
local "number
make "number random :max
local "guesses
make "guesses 0
local "guess
forever [
(type [Guess my number! \(range 1 -\ ] :max "\):\ )
make "guess first readlist
ifelse (or (not numberp :guess) (lessp :guess 1) (greaterp :guess :max)) [
print sentence [Guess must be a number between 1 and] (word :max ".)
] [
make "guesses (:guesses + 1)
ifelse lessp :guess :number [
print [Too low!]
] [ifelse equalp :guess :number [
(print [You got it in] :guesses "guesses!)
stop
] [
print [Too high!]
]]
]
]
end
You may also check:How to resolve the algorithm User input/Text step by step in the OCaml programming language
You may also check:How to resolve the algorithm Archimedean spiral step by step in the SAS programming language
You may also check:How to resolve the algorithm Bitwise operations step by step in the Action! programming language
You may also check:How to resolve the algorithm Associative array/Creation step by step in the Maple programming language
You may also check:How to resolve the algorithm Range expansion step by step in the COBOL programming language