zoukankan      html  css  js  c++  java
  • while loop

    有一种循环叫死循环,一经触发,就运行个天荒地老、海枯石烂

    海枯石烂代码

    count = 0
    while True:
        print("你是风儿我是沙,缠缠绵绵到天涯...",count)
        count +=1    # 相当于 count = count +1

    其实除了时间,没有上面是永恒的,死loop还是少写为好

    上面的代码循环100次就退出吧

    count = 0
    while True:
        print("你是风儿我是沙,缠缠绵绵到天涯...",count)
        count +=1
        if count == 100:
            print("去你妈的风和沙,你们这些脱了裤子是人,穿上裤子是鬼的臭男人..")
            break
    View Code

    回到上面的for循环的例子,如何实现让用户不断的才年龄,但只给最多3次机会,再猜不对就退出程序。

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
     
     
    my_age = 28
     
    count = 0
    while count < 3:
        user_input = int(input("input your guess num:"))
     
        if user_input == my_age:
            print("Congratulations, you got it !")
            break
        elif user_input < my_age:
            print("Oops,think bigger!")
        else:
            print("think smaller!")
        count += 1 #每次loop 计数器+1
    else:
        print("猜这么多次都不对,你个笨蛋.")
    View Code
  • 相关阅读:
    模块二:操作系统windows 7 的使用
    茶卡盐湖
    css元素居中指南
    新的CMS套站
    写响应式页面
    积累
    jquery方法整理
    积累 做网站添加的 所有动态效果
    产品中心有二级三级栏目。
    aspcms
  • 原文地址:https://www.cnblogs.com/lzhn/p/7805857.html
Copyright © 2011-2022 走看看