perl practice

cp /home/users/ericli/.profile .

1)      Copy my file/home/users/ericli/.profile  to your path.

   




  1#!usr/local/bin/perl5 -w

      2use strict;

      3use warnings;

      4my $a;

      5my $g;

      6$a = 12.5;

      7$g = 2*12.5*3.14;

      8print "$g\n";

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

0mnsdev13:scripts> ls

FASTA.PL                  fasta.pl

FASTA.out                 file/

FASTA.pk                  lianxi.pl

FASTA.pl                  oekb_xml_download_url.pl

FASTAFASTA.pl             oekb_xml_parse_load.pl

FASTa.pl                  pl

mnsdev13:scripts> perl5FASTA.pl

78.5

mnsdev13:scripts>

 

2)

      1#!usr/local/bin/perl5 -w

      2use strict;

      3use warnings;

      4my $a;

      5my $g;

      6$@ =12.5;

      7chomp($a=<STDIN>);

     8     $g = 2*$a*3.14;

      9print "$g\n";

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

0mnsdev13:scripts> ls

FASTA.PL                  fasta.pl

FASTA.out                 file/

FASTA.pk                  lianxi.pl

FASTA.pl                  oekb_xml_download_url.pl

FASTAFASTA.pl             oekb_xml_parse_load.pl

FASTa.pl                  pl

mnsdev13:scripts> perl5FASTA.pl

0

0

mnsdev13:scripts> perl5FASTA.pl

3

18.84

mnsdev13:scripts>

 

 

3)

      1#!usr/local/bin/perl5 -w

      2use strict;

      3use warnings;

      4my $a;

      5my $g;

      6chomp($a=<STDIN>);

      7if($a<0){

     8     $g=0;

      9}

     10else{

    11     $g = 2*$a*3.14;

     12 }

     13print "$g\n";

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

0mnsdev13:scripts> ls

FASTA.PL                  fasta.pl

FASTA.out                 file/

FASTA.pk                  lianxi.pl

FASTA.pl                  oekb_xml_download_url.pl

FASTAFASTA.pl             oekb_xml_parse_load.pl

FASTa.pl                  pl

mnsdev13:scripts> perl5FASTA.pl

0

0

mnsdev13:scripts> perl5FASTA.pl

22

138.16

 

4)

 

      1#!usr/local/bin/perl5 -w

      2use strict;

      3use warnings;

      4my $a;

      5my $g;

      6my $c;

      7$@ =12.5;

      8chomp($a=<STDIN>);

      9chomp($g=<STDIN>);

    10     $c = $a*$g;

     11print "$c\n";

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

0mnsdev13:scripts> ls

FASTA.PL                  fasta.pl

FASTA.out                 file/

FASTA.pk                  lianxi.pl

FASTA.pl                  oekb_xml_download_url.pl

FASTAFASTA.pl             oekb_xml_parse_load.pl

FASTa.pl                  pl

mnsdev13:scripts> perl5FASTA.pl

1

4

4

mnsdev13:scripts>

 

5)

 

      1#!usr/local/bin/perl5 -w

      2use strict;

      3use warnings;

      4my $a;

      5my $g;

      6my $c;

      7$@ =12.5;

      8$a=<STDIN>;

      9$g=<STDIN>;

    10     $c = $a x $g;

     11print "$c";

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

~                                                                             

0mnsdev13:scripts> ls

FASTA.PL                  fasta.pl

FASTA.out                 file/

FASTA.pk                  lianxi.pl

FASTA.pl                  oekb_xml_download_url.pl

FASTAFASTA.pl             oekb_xml_parse_load.pl

FASTa.pl                  pl

mnsdev13:scripts> perl5FASTA.pl

r

5

r

r

r

r

r

mnsdev13:scripts> perl5FASTA.pl

perl

3

perl

perl

perl

mnsdev13:scripts>

 

 


 

1)     写一个程序,计算半径为12.5的圆的周长。

2)     修改上述程序,用户可以在程序运行时输入半径。如果,用户输入12.5,则应得到和上题一样的结果

3)     修改上述程序,当用户输入小于0的数字时,程序输出的周长为0,而非负数

4)     写一个程序,用户能输入2个数字(不在同一行)。输出为这两个数的积

5)     写一个程序,用户能输入1个字符串和一个数字(n)(不在同一行)。输出为,n行这个字符串

例如,如果用户输入的是fred3”,则输出为:3行,每一行均为fred。如果输入为fred299792”,则输出为299792行,每一行均为fred

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值