jonvi 发表于 2018-9-1 07:12:50

perl写的猜数游戏

  


[*]#!/usr/bin/perl
[*]
[*]use strict;
[*]
[*]my $count=0;
[*]
[*]print "please input a number between 0-10000 which is int.\n";
[*]
[*]$rand_num=int (rand(10000));
[*]
[*]do{
[*]
[*]      $count++;
[*]
[*]      chomp( $input_num=);
[*]
[*]
[*]      if ($input_num >$rand_num){
[*]
[*]                print "You enter the nubmer is lager than real number.please go on\n";
[*]
[*]}
[*]
[*]      else { print "you enter the nubmer is smaler than real number.please go on\n";}
[*]
[*]}while ($input_num != $rand_num);
[*]
[*]
[*]print "Right,you only use $count step to cmp!\n";
  

  自己自学perl以来,自己写的第一个perl程序。在网上看到别人写的一个猜数游戏,知道其原理后,自己也写了一段代码。欢迎大家拍砖。


页: [1]
查看完整版本: perl写的猜数游戏