码迷,mamicode.com
首页 > 其他好文 > 详细

while循环

时间:2018-07-03 21:33:57      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:学习   基础   NPU   开始   执行流程   流程   xxx   运算   pytho   

循环. while循环
        while 条件:
            代码块(循环体)
        执行流程:
            1. 判断条件是否为真. 如果真. 执行代码块
            2. 再次判断条件是否为真......
            3. 当条件为假.执行else 跳出循环. 循环结束

# 计数
# count = 1
# while count <= 8:
#     print("你是alex么?")
#     print("你才是太白")
#     count = count + 1

# 让用户尽情的喷. 输入q退出
# while True:
#     s = input("请开始喷:")
#     if s == ‘q‘:
#         break   # 停止当前循环
#     # 过滤掉马化腾
#     if  "马化腾" in s: # 在xxx中出现了xx
#         print("你输入的内容和草泥马有一拼. 不能输出")
#         continue    # 停止当前本次循环. 继续执行下一次循环
#     print("喷的内容是:"+s)

# 1+2+3+4+5+6+7+8....+100 = ?
# count = 1
# # 准备一个变量
# sum = 0
# while count <= 100:
#     # 累加到sum中
#     sum = sum + count   # 把sum中的值(之前运算的结果)和当前数的数相加
#     count = count + 1
# print(sum)

# 输出1-100所有的奇数.
# count = 1
# while count <= 100:
#
#     if count % 2 != 0:
#         print(count)
#
#     count = count + 1

  

‘‘‘while True :
    s = input ("请开始喷:")
    if s == ("q"):
        break    #停止当前循环
    if "啦啦啦" in s:
        print("你输入的内容包含敏感字符,请重新输入.")
        continue
    print(s)

count = 1
sum = 0
while count <= 100:
    count = count + 1
    sum = sum + count
print(sum)


#   2的倍数相加   加到100

count = 2
sum = 0
while count <= 100:
    sum = sum + count
    count = count + 2
print(sum)


count = 1
while count <= 100:
    if count % 2 == 1:
        print(count)
    count = count + 1


    while True:
    s = input("请输入你要输入的内容")
    if "啦啦啦" in s:
        print("你输入的内容包含敏感字符,请重新输入")
        continue
    if s == ("q"):
        break
    print(s)

sum = 0
count = 1
while count <= 100:
    count = count + 1
    sum = count + sum
print(sum)

count = 1
while count <= 100:
    if count % 2 != 0:
        print(count)
    count = count + 1‘‘‘

‘‘‘while True:
    s = input("请输入")
    if "啦啦啦" in s
        print("非法字符")
    if s == ("q"):
        break
    print(s)
‘‘‘
‘‘‘count = 1
sum = 0
while count <= 100:
    count = count +1
    sum = sum + count
print(sum)‘‘‘

‘‘‘count = 1
while count <= 100:
    if count % 2 != 0:
        print(count)
    count= count + 1‘‘‘
name = input("请输入你的名字")
age = input("请输入你的年龄")
print("我叫%s, 今年%s岁了,我们已经学习了了2%%的python基础了" % (name,age))

  

while循环

标签:学习   基础   NPU   开始   执行流程   流程   xxx   运算   pytho   

原文地址:https://www.cnblogs.com/w-y-z/p/9260504.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!