Guess the number/With feedback (player): Difference between revisions
Content deleted Content added
MaiconSoft (talk | contribs) Added Delphi example |
Added Wren |
||
Line 3,382: | Line 3,382: | ||
End Sub |
End Sub |
||
</lang> |
</lang> |
||
=={{header|Wren}}== |
|||
<lang ecmascript>import "io" for Stdin, Stdout |
|||
import "random" for Random |
|||
var rand = Random.new() |
|||
var n = rand.int(1, 21) // computer number from 1..20 inclusive, say |
|||
System.print("The computer has chosen a number between 1 and 20 inclusive.") |
|||
while (true) { |
|||
System.write(" Your guess 1-20 : ") |
|||
Stdout.flush() |
|||
var g = Num.fromString(Stdin.readLine()) |
|||
if (!g || g.type != Num || !g.isInteger || g < 1 || g > 20) { |
|||
System.print(" Inappropriate") |
|||
} else if (g > n) { |
|||
System.print(" Too high") |
|||
} else if (g < n) { |
|||
System.print(" Too low") |
|||
} else { |
|||
System.print(" Spot on!") |
|||
break |
|||
} |
|||
}</lang> |
|||
{{out}} |
|||
Sample session: |
|||
<pre> |
|||
The computer has chosen a number between 1 and 20 inclusive. |
|||
Your guess 1-20 : 21 |
|||
Inappropriate |
|||
Your guess 1-20 : 1.5 |
|||
Inappropriate |
|||
Your guess 1-20 : abc |
|||
Inappropriate |
|||
Your guess 1-20 : 10 |
|||
Too low |
|||
Your guess 1-20 : 15 |
|||
Too high |
|||
Your guess 1-20 : 13 |
|||
Too high |
|||
Your guess 1-20 : 12 |
|||
Too high |
|||
Your guess 1-20 : 11 |
|||
Spot on! |
|||
</pre> |
|||
=={{header|XPL0}}== |
=={{header|XPL0}}== |