python的while分支

tech2025-10-23  2

python的while分支

1、输出0到100,50不输出,60到90是输出平方

代码

count=0 while count<=49: print("loop",count) count+=1 if count==50: pass count+=1 while count>=51 and count<=59: print("loop",count) count+=1 while count>=60 and count<=90: print("loop",count*count) count+=1 while count>90 and count<=100: print("loop",count) count+=1

运行结果 运行结果是对的,但是程序有些不简洁

修改后的代码为

count=0 while count<=100: if count==50: pass elif count>=60 and count<=90: print("loop",count*count) else: print("loop",count) count+=1

运行结果

最新回复(0)