python10.24

30 阅读1分钟
 # while 循环基础
count = 1 # 初始值
while count <= 5:
    print("我在学习while循环")
    count += 1 # count = count + 1

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


        count += 1  # count = count + 1
        print("总和为:",total)

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

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


    # 计算50以内所有能被7整除的数的和
        count = 7  # 初始值
        total = 0  # 总和的初始值
        while count <= 50:
            total += count  # total = total + count
            print(count)
            count += 7  # count = count + 2
        print("总和为:", total)

    # 计算100以内所有能被3和5整除的数的和
        count = 7  # 初始值
        total = 0  # 总和的初始值
        while count <= 50:
            total += count  # total = total + count
            print(count)
            count += 7  # count = count + 2
        print("总和为:", total)


```c
# 逻辑运算符
   x = 0
   y = 1
   a = 0
   b = 2
   # and
   c =x and y
   c =y and x
   c =x and a
   c =y and b
   print(c)
   #or
   c = x or y
   c = y or x
   c = x or a
   c = y or b
   print(c)
   #not
   c = not a
   c = not b
   print(c)