#下图为到三角: num=5while num>0: tem=num while tem>0: #嵌套循环 print("#",end=" ") tem-=1 print() num-=1 #a=1000 b=a b=1000 a=900
九九乘法表:
倒序: first=9#second=9while first>0: tem=1 while tem<=first: # print(tem,"*",first,"=",first*tem,end=" ") print(str(tem)+"*"+str(first)+"="+str(first*tem),end="\t") #\t是制表符 \n是换行 print()默认换行 tem+=1 #print(first,"*",first,"=",first) print() first-=1 正序: first=1#second=9while first<=9: tem=1 while tem<=first: # print(tem,"*",first,"=",first*tem,end=" ") print(str(tem)+"*"+str(first)+"="+str(first*tem),end="\t") #第二行是数字强转字符串,通过+连接起来 tem+=1 #print(first,"*",first,"=",first) print() first+=1
a>b yi #>因为旁边有两个数字,所以被称为二幕运算符或者二元运算符。
not a>b #not 因为右边只有一个整体,所以被称为一幕运算符或者一元运算符
#and not or 运算符优先级用()来表示。
while 条件1:
..........
while 条件2:
..........
break 中断某次循环
continue 跳过当次循环
#while 循环结构:
while 判断条件:
执行语句....
else:
执行语句...
while循环else语句比较特殊,只有正常结束条件(非break)下才会执行。