1. 程式人生 > >python的for迴圈、while迴圈

python的for迴圈、while迴圈

1、for迴圈使用之乘法表

for i in range(1,10):
    for j in range(1,i+1):
        print('%s * %s = %s  '%(j,i,i*j),end='')
    print(end='\n')

 

2、while 迴圈之20以內奇數輸出

count = 0
while count <= 20:
    if count %2 != 0:
        print(count)
    count = count + 1