1. 程式人生 > >乘法表(python與shell)

乘法表(python與shell)

#乘法表(python):

num = (1,2,3,4,5,6,7,8,9)
for x in (num):
    for y in (num):
        if y <= x :
            z = y * x
            print('%s * %s = %s' % (y ,x,z),' ',end='')
            if y == x:
                print('')

#乘法表(shel):

i=1;
while [ $i -le 9 ] ;do
        j=1;
        while [ $j -le $i ] ;do
                sum=$( expr $i \* $j );
                echo -ne "$j x $i = $sum \t";
                j=$(expr $j + 1);
        done
echo #換行;
i=$(expr $i + 1);
done