Python从0到100:Python分支结构和循环结构
    		       		warning:
    		            这篇文章距离上次修改已过449天,其中的内容可能已经有所变动。
    		        
        		                
                
# Python 分支结构示例
temperature = 20
if temperature < 0:
    print("冰冷")
elif temperature < 10:
    print("寒冷")
else:
    print("温暖")
 
# Python 循环结构示例
for i in range(5):  # 从0到4
    print(f"当前数字是{i}")
 
# Python 循环中的else块
for i in range(5):
    if i == 3:
        break
    print(f"当前数字是{i}")
else:
    print("没有被break中断的循环执行完毕")
 
# Python 无限循环结构示例
while True:
    answer = input("是否继续?(y/n) ")
    if answer.lower() == 'n':
        print("程序结束")
        break这段代码展示了Python中的分支结构(if-elif-else)和循环结构(for,while),以及for循环中的else块用法。
评论已关闭