现在的位置: 首页 > 综合 > 正文

perl版本猜数字

2013年10月23日 ⁄ 综合 ⁄ 共 351字 ⁄ 字号 评论关闭
use diagnostics;
use 5.010;
$num = int(1 + rand 100);
print "input guess number here with 10 times: \n";
while(<STDIN>){
	$times++ if $_=~ /\d+/;
	if($times > 10 || $_ =~ /^[quit|exit]/i){
		print "the real number you was just guessing is $num\n";
		print "You've try $times times.\n";
		last;
	}
	print "Too high\n" if $_ > $num;
	print "Too low.\n" if $_ < $num;
	print "You're so great, you get it with $times times.\n" if $_ == $num;
}

抱歉!评论已关闭.