Python条件循环语句
while 条件表达式: 循环体
当条件表达式为真时,执行循环体,
执行循环体后,再判断条件表达式真假,
真到条件表达式为假时,退出循环。
例子一
#只要x小于6就打印x x = 1 while x < 6: print(x) x += 1
例子二
#黄蓉难倒瑛姑题 print("今有一数,三三数之剩二,五五数之剩三,七七数之剩二,问几何?") panduan = 1 shu = 0 while panduan: shu += 1 if (shu % 3 == 2) and (shu % 5 == 3) and (shu % 7 == 2): print("这个数是:" , shu) panduan = 0
2022-02-24 21:10:37 星期四
本站已禁止评论!!! 如文章错漏请给博主写信或微信联系。