..............................................................................................................................................................................................................................................................................................................................
1.关于循环:while--for对比
1.1 基本语句:
num = 1 ------------------------------------------------------------------------------------ 无需变量
while num<=10:---------------------------------------------------------------------------- for cyc in range( 1 , 11 ):
(代码 eg:print(“good evening!”))----------------------------------------- (代码 eg:print(“good evening!”))
..............................................................................................................................................................................................................................................................................................................................
1.2九九乘法表:
num=1-------------------------------------------------------------------------------------- 无需变量
while num<=9:----------------------------------------------------------------------------- for out_cyc in range( 1 , 10 ):
num2=1----------------------------------------------------------------------------- 无需变量
while num2<=num :---------------------------------------------------------------- for inner_cyc in( 1 , out_cyc ):
print("%d * %d = %d " % (num2,num1,num1*num2) , end = " ")--------- print("%d * %d = %d " % (num2,num1,num1*num2) , end = " ")
num2 += 1-------------------------------------------------------------------
num1 += 1--------------------------------------------------------------------------
print("")------------------------------------------------------------------------------ print("")
..............................................................................................................................................................................................................................................................................................................................
1.3 金字塔形状:
-
* - for cyc1 in range(1,7):
*** - print(" " * (7-cyc) , end = " ")
***** - for cyc2 in range(1, ((2*cyc1)-1) ):
******* - print ("*" * ((2*cyc1)-1) , end = " ")
********* - print(“”)
*********** -
..............................................................................................................................................................................................................................................................................................................................
|
|