根据下面的代码,我应该bibhu打印一次,j如果我在运行时输入"bibhu",则应该为1.但它没有发生.我为什么要来j=0?
print "enter\n";
$find=<STDIN>;
$j=0;
@lines=qw(bibhu prasanna behera kuni shun jbjdkj);
foreach (@lines) {
if ($_ =~ /$find/) {
print "$_\n";
$j=$j+1;
}
}
print "$j\n";
Run Code Online (Sandbox Code Playgroud) 我的节目是 -
@arr=('1','1 1');
print "enter the number of rows\n";
$rows=<STDIN>;
$v=0;
while($v<$rows)
{
foreach $ele (@arr)
{
@arr1=split(/\s+/,$ele);
$g=@arr1;
#print "$g\n";
$i=0;
$j=1;
$str='';
while ($j<$g)
{
$res=$arr1[$i]+$arr1[$j];
#print "$res\n";
$i=$1+1;
$j=$j+1;
$str=$str.' '.$res;
}
$final='1'.' '.$str.' '.'1';
print "$final\n";
}
$v=$v+1;
#@arr=();
push(@arr,$final);
}
print "@arr";
foreach (@arr)
{
print "$_\n";
}
Run Code Online (Sandbox Code Playgroud)
我的输出是:
C:\Perl\bin>perl pascal.pl
enter the number of rows
4
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 …Run Code Online (Sandbox Code Playgroud) list1=[1,3,8,10,23,8,8,10,23,3,8,10,23,3,8,10,23]
list2=[10,23,3]
cnt=list1.count(list2[0])
cnt1=1
j=0
while (cnt1<=cnt):
list3=[]
list3.append(list2[0])
i=1
k=list1.index(list2[0])
while (i<len(list2)):
list3.append(list1[k+i])
i=i+1
print (list3)
if (list2==list3):
print ("list2 is a subset")
j=j+1
else:
print ("list2 is not a subset")
list1.remove(list2[0])
cnt1=cnt1+1
print (list2,"occurs",j,"times")
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误.
Run Code Online (Sandbox Code Playgroud)Traceback (most recent call last): File "C:\Python26\Lib\idlelib\sublist.py", line 12, in <module> list3.append(list1[k+i]) IndexError: list index out of range"