2025.10.22Python笔记

35 阅读1分钟

while循环基础

count = 1 #初始值 while count<=5: print ("我在学习while循环") count += 1 # count = count + 1

#累加计算 count = 1 total = 0 # 总和的初始值 while count<=100: total += count print(count) count += 1 # count = count + 1 print("总和为:",total)

#喝水 """ cup = 1 #初始值 target = 8 while cup <= target: a = input() print(f"喝了第{cup}杯水") cup += 1 print("喝水任务完成") """

count = 1 total = 0 while count <= 100: total += count print(count) count += 2 print("总和为:",total)

#计算100以内所有能被3和5整除的数的和 count = 1 total = 0 while count <= 100: if count % 15 == 0: total += count print(count) count += 1 print("总和为:",total)

x = 0 y = 1 a = False b = 2 c = x and y c = y and x print(c) c = x and a c = a and x

image.png

image.png