i = 1 while i <=5: print("*"*i) i +=1 小星星进行循环
row=1 (定义初始行) while row<=5: col = 1 (定义初始列) while col<=row: print("* ",end="") col+=1 (控制条件) print() (自动换行) row+=1 (控制条件)
99乘法标
row=1 while row<=9: col = 1 while col<=row: #print("%d*%d=%d" %(col,row,row*col),end="\t") 方法一 #print(f"{col}*{row}={row*col}", end="\t") 方法二 print("{}*{}={}".format(row,col,row*col),end="\t") 方法三 col+=1 print() row+=1
用for循环来计算1到100的值
sum=0 for i in range (1,101): sum=i + sum print(f"求和结果为{sum}")
continue循环