#!/usr/bin/env tclsh
proc rand_range {min max} {
return [expr int(rand()*($max-$min+1)) + $min]
}
set answer [rand_range 1 1000]
while {1} {
puts -nonewline "Please input a number to guess (1-1000): "
flush stdout
gets stdin guess
if {$guess == $answer} {
break;
} else {
if {$guess < $answer} {
puts "Please guess more higher"
} else {
puts "Please guess more lower"
}
}
}
沒有留言:
張貼留言