python与Javascript做了九九乘法表,并且进行了对比

194 阅读1分钟

九九乘法表

  • 使用python中的while循环去做:\color{red}{使用python中的while循环去做:}

i = 1   #i表示行
while i <= 9:
    j = 1    #j表示列 
    while j <= i:
     print( f'{j}*{i}={j*i}',end='' )
     j +=1
    print()
    i +=1
  • 使用python中的for循环去做:\color{red}{使用python中的for循环去做:}


for i in range(1,10):
    for j in range(1,i+1):
     print('{}*{}={}\n'.format(i,j,i*j),end='')
print() 
 
  • 使用Javascript中的for循环去做:\color{red}{使用Javascript中的for循环去做:}

for (let i = 1; i <= 9; i++) { //i表示行
      for (let j = 1; j <= i; j++) { //j表示列 
        var bird = j + '*' + i + '=' + i * j //进行拼接
        console.log(bird); 
      }
    }