x=1
sum_flowers =0for x inrange(1,101):print(f"第{x}天表白:")for y inrange(1,11):print(f"送{y}玫瑰花")
sum_flowers=sum_flowers+y
print("ikun")print(f"{x}天表白成功IKUN,一共送{sum_flowers}朵玫瑰花")
示例2:打印九九乘法表
for与while的嵌套:
for x inrange(1,10):
y=1while y<=x:print(f"{y}*{x}=%d\t"%(y*x),end='')
y+=1print(" ")
输出结果:
1*1=11*2=22*2=41*3=32*3=63*3=91*4=42*4=83*4=124*4=161*5=52*5=103*5=154*5=205*5=251*6=62*6=123*6=184*6=245*6=306*6=361*7=72*7=143*7=214*7=285*7=356*7=427*7=491*8=82*8=163*8=244*8=325*8=406*8=487*8=568*8=641*9=92*9=183*9=274*9=365*9=456*9=547*9=638*9=729*9=81
for与for的嵌套:
for x inrange(1,10):for y inrange(1,x+1):print(f"{y}*{x}=%d\t"%(y*x),end='')
y+=1print(" ")
输出结果:
1*1=11*2=22*2=41*3=32*3=63*3=91*4=42*4=83*4=124*4=161*5=52*5=103*5=154*5=205*5=251*6=62*6=123*6=184*6=245*6=306*6=361*7=72*7=143*7=214*7=285*7=356*7=427*7=491*8=82*8=163*8=244*8=325*8=406*8=487*8=568*8=641*9=92*9=183*9=274*9=365*9=456*9=547*9=638*9=729*9=81