美文网首页
循环就是这么简单

循环就是这么简单

作者: 微尘_ffb0 | 来源:发表于2019-12-20 11:44 被阅读0次

1,while

检测输入的值 是否合适的,while简单应用。

_age = 30
count = 0
total = 3
while count < total:
    age = int(input("guess age : "))
    if _age < age:
        print("it's larger")
    elif _age == age:
        print("you got it")
        break
    else:
        print("it's smaller")

    count += 1
    if total - count > 0:
        print("you  already left %d times" % (total - count))
else:
    print("you have already used all your chance, Bye"

or 不带else的常规用法

_age = 30
count = 0
total = 3
while count < total:
    age = int(input("guess age : "))
    if _age < age:
        print("it's larger")
    elif _age == age:
        print("you got it")
        break
    else:
        print("it's smaller")

    count += 1
    if total - count > 0:
        print("you  already left %d times" % (total - count))

2,for
for循环的用法

for i in range(0,10,2):
    print(i)

_age = 2

count = 0
total = 3

for i in  range(3):
    age = int(input("guess age : "))
    if _age < age:
        print("it's larger")
    elif _age == age:
        print("you got it")
        break
    else:
        print("it's smaller")

    if total - i-1 > 0:
        print("you  already left %d times" % (total - count))
else:
    print("you have already used all your chance, Bye")

相关文章

  • 循环就是这么简单

    1,while 检测输入的值 是否合适的,while简单应用。 or 不带else的常规用法 2,forfor循环的用法

  • 【就是这么简单】

    當你相信簡單再困難也很簡單 當你害怕困難再簡單也很困難 路是一條波動的拋物線相信簡單起伏便會變成動人的旋律 我們必...

  • 2018-12-21

    干活,往外面扔, 留您的朋友圈,有广告,就成交了。 人生就是这么简单。 简单+重复,不断的循环, 就是营销。 您们...

  • iOS runloop与多线程

    一、RunLoop是什么? 事件循环,绝对不止是死循环这么简单的一个回答。实质上就是runloop内部状态的转换。...

  • XML就是这么简单

    什么是XML? XML:extensiable markup language 被称作可扩展标记语言 XML简单的...

  • SpringBoot就是这么简单

    一、SpringBoot入门 今天在慕课网中看见了Spring Boot这么一个教程,这个Spring Boot作...

  • Activiti就是这么简单

    Activiti介绍 什么是Activiti? Activiti5是由Alfresco软件在2010年5月17日发...

  • 阅读,就是这么简单

    近年来,媒体时常会有报道指出,现在的中国人不爱阅读,罗列出来的数据很是触目惊心。姑且不论报导数据的真实性如何,人们...

  • Lucene就是这么简单

    什么是Lucene?? Lucene是apache软件基金会发布的一个开放源代码的全文检索引擎工具包,由资深全文检...

  • Promise 就是这么简单

    Promise 是干嘛的? Promise是ES6针对js异步编程一种解决方案,也解决了ES5之前异步编程大量回调...

网友评论

      本文标题:循环就是这么简单

      本文链接:https://www.haomeiwen.com/subject/hegbnctx.html