美文网首页
Chapter 07:用户输入和while循环

Chapter 07:用户输入和while循环

作者: 蜜糖_7474 | 来源:发表于2018-12-14 20:41 被阅读0次

    input内字符串参数是提示文字

    msg = input("human nature:")
    print(msg)
    

    human nature:repeater
    repeater

    input获取的数据类型为字符串类型,int()函数可将字符串类型的数字转化为int型

    age = int(input())
    print(age > 18)
    

    19
    True

    while循环

    cur_num = 1
    while cur_num <=5:
        print(cur_num)
        cur_num += 1
    

    1
    2
    3
    4
    5

    python不支持注释内的写法

    #while (msg = input()) != 'quit':
    #    print(msg)
    msg = ''
    while msg != 'quit':
        msg = input()
        print(msg)
    

    lajd
    lajd
    laksjd
    laksjd
    quit
    quit

    break和continue都是人如其名

    nums = [1, 2, 3, 4, 5, 6, 7]
    for num in nums:
        if num % 2 == 0:
            continue
        elif num == 5:
            break;
        else:
            print(num)
    

    1
    3

    相关文章

      网友评论

          本文标题:Chapter 07:用户输入和while循环

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