Python学习系列 ( 第二章):Py

发布时间:2019-06-28 17:46:47编辑:auto阅读(1094)

    一:Python的用户输入:

      1.1 Python的输入

     

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # Author:FlyFish
    
    #import getpass
    
    _username = "zhangyy"
    _password = "abc123"
    
    username = input("username:")
    password = input("password:")   ### password = getpass.getpass("password:")
    
    if _username == username and _password == password:
       print("Welcom user {name} login".format(name=username))
    else:
        print("Invalid username or password ")

    wKiom1lSFILSz8euAAB2JtwHSnE758.png-wh_50

    二:if....else 循环:

     在程序里设定好你的年龄,然后启动程序让用户猜测,用户输入后,根据他的输入提示用户输入的是否正确,如果错误,提示是猜大了还是小了


     注释:

      

       外层变量,可以被内层代码使用

       内层变量,不应被外层代码使用

     

    #!/usr/bin/env python
    
    # -*- coding: utf-8 -*-
    
    # Author:FlyFish
    
    age_of_zhangyy = 26
    
    guess_age = int(input("guess zhangyyy age:"))
    
    if guess_age == age_of_zhangyy:
        print("yes,yo go it")
    elif guess_age > age_of_zhangyy:
        print("think smaller...")
    else:
        print("think bigger")

    wKiom1lSGTGCYPg3AAZNMOpz9po926.png-wh_50

    三:while的循环

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # Author:FlyFish
    
    count = 0
    
    while True:
        print("count",count)
        count = count + 1

    wKioL1lSGcaQmQDOAALBuxWHaK8613.png-wh_50

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # Author:FlyFish
    age_of_zhangyy = 26
    count = 0
    while True:
        if count == 3:
            break
        guess_age = int(input("guess zhangyyy age:"))
        if guess_age == age_of_zhangyy:
            print("yes,yo go it")
            break
        elif guess_age > age_of_zhangyy:
              print("think smaller...")
        else:
            print("think bigger")
        count+=1

    wKiom1lSGiugoX3pAAK4fm_C49Y652.png-wh_50

    #!/usr/bin/env python
    
    # -*- coding: utf-8 -*-
    
    # Author:FlyFish
    
    age_of_zhangyy = 26
    count = 0
    while count<3:
    
        guess_age = int(input("guess zhangyyy age:"))
    
        if guess_age == age_of_zhangyy:
            print("yes,yo go it")
            break
        elif guess_age > age_of_zhangyy:
              print("think smaller...")
        else:
            print("think bigger")
        count+=1
    
        if count ==3:
            countine_confirm = input("do you want to guessing....")
            if countine_confirm !='n':
                count ==0
    
    else:
        print("you have tried too many times..fuck off")


    wKiom1lSGufCIjKrAAOJa8UsP84766.png-wh_50


    三:Python的模块知识:

      Python的强大之处在于他有非常丰富和强大的标准库和第三方库,几乎你想实现的任何功能都有相应的Python库支持,以后的课程中会深入讲解常用到的各种库,现在,我们先来象征性的学2个简单的。







关键字