How to resolve the algorithm Guess the number/With feedback step by step in the Raku 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 Raku 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 Raku programming language
Source code in the raku programming language
my $maxnum = prompt("Hello, please give me an upper boundary: ");
until 0 < $maxnum < Inf {
say "Oops! The upper boundary should be > 0 and not Inf";
$maxnum = prompt("Please give me a valid upper boundary: ");
}
my $count = 0;
my $number = (1..$maxnum).pick;
say "I'm thinking of a number from 1 to $maxnum, try to guess it!";
repeat until my $guessed-right {
given prompt("Your guess: ") {
when /^[e|q]/ { say 'Goodbye.'; exit; }
when not 1 <= $_ <= $maxnum {
say "You really should give me a number from 1 to $maxnum."
}
$count++;
when $number { $guessed-right = True }
when $number < $_ { say "Sorry, my number is smaller." }
when $number > $_ { say "Sorry, my number is bigger." }
}
}
say "Great you guessed right after $count attempts!";
You may also check:How to resolve the algorithm Compound data type step by step in the Ursala programming language
You may also check:How to resolve the algorithm Day of the week step by step in the jq programming language
You may also check:How to resolve the algorithm Sum digits of an integer step by step in the Miranda programming language
You may also check:How to resolve the algorithm Guess the number step by step in the REXX programming language
You may also check:How to resolve the algorithm Cumulative standard deviation step by step in the AppleScript programming language