条件循环
a = 9
if a>5:
print("你猜错了")
else:
print("你猜对了")
print("你猜对了") if a>5 else print("你猜错了")
print("你猜对了" if a > 5 else "你猜错了")
tong = "你猜对了" if a > 5 else "你猜错了"
print(tong)
#自增量
a = 1
#循环条件
while a<5:
print("我是童谣%s"%a)
#自增
a +=1
print('程序已结束')
计算1-100 的和。高斯求和
1+2+3+4+5+6.....+100
#自增量
count = 1
#使用一个变量对结果进行保存
sum = 0
#循环条件
while count<=100:
sum = sum + count
print(count,sum)
自增
count +=1
嵌套循环
i = 0
while i<5:
print(f'+++{i}')
j = 0
while j < 5:
print(f'---{j}')
j += 1
i+=1
外层循环执行一次,内层循环执行5次
i = 0
while i <= 10:
if i ==3:
i += 1
continue
break
print(i)
i += 1
i = 0
while i <= 10:
if i != 3:
print(i)
i += 1