zoukankan      html  css  js  c++  java
  • 4、Python相关用法

    1. 输入,输出

    #!/usr/bin/python
    # -*- coding:utf-8 -*-
    
    v = input(">>>")
    import getpass
    v = getpass.getpass('>>>')
    print(v)
    

      


    2. 条件语句

    if 条件:
    成功走这里
    else:
    失败走着


    应用:


    import getpass

    name = input("请输入姓名:")
    pwd = getpass.getpass('请输入密码:')
    if name == 'deasion' and pwd == '123':
    print('欢迎登陆')
    else:
    print('滚蛋')



    if 条件:
    ...
    elif 条件:
    ...
    else:
    ...

    应用:
    username = input('>>>')
    if username == 'alex':
    print('普通管理')
    elif username == 'oldboy':
    print('超级管理')
    elif username == '郭少龙':
    print('人')
    elif username == '刘一':
    print('装逼犯')
    else:
    print('再见...')

    print('end')


    3. 循环语句

    while 条件:
    continue # 立即开始下次循环
    break # 跳出所有循环


    4. 练习:
    1)、使用while循环输入 1 2 3 4 5 6 8 9 10

    i = 1
    while i < 11:
        if i == 7:
            i += 1
            continue
        print(i)
        i += 1
    

      

    2)、求1-100的所有数的和

    value = 0
    i = 1
    while i < 101:
        value += i
        i += 1
    print(value)
    # 3、输出1 - 100内的所有奇数
    i = 1
    while i < 101:
        if i % 2 == 1:
            print(i)
        i += 1
    

      

    3)、输出 1-100 内的所有奇数

    i = 1
    while i < 101:
        if i % 2 == 1:
            print(i)
        i += 1
    

      

    4)、输出 1-100 内的所有偶数

    i = 1
    while i < 101:
        if i % 2 == 0:
            print(i)
        i += 1
    

      

    5)、求1-2+3-4+5 ... 99的所有数的和

    value = 0
    i = 1
    while i < 100:
        if i % 2 == 1:
            value += i
        else:
            value -= i
        i += 1
    print(value)
    

      

    6)、用户登陆(三次机会重试)

    i = 0
    while i < 3:
        user = input("请输入用户名:")
        pwd = input("请输入密码:")
        if user == 'deasion' and pwd == '123':
            print('登陆成功')
            break
        else:
            print("用户名或密码错误,请重新输入!")
            i += 1
    print("已输入错误3次,已锁定!")
    

      

  • 相关阅读:
    Java 代理模式
    ReentrantLock 详解
    Java线程池详解
    ConcurrentHashMap 解读
    CountDownLatch/CyclicBarrie用法记录
    微信接入笔记记录
    iOS设计模式
    iOS设计模式
    iOS设计模式
    iOS设计模式
  • 原文地址:https://www.cnblogs.com/deasion/p/6814737.html
Copyright © 2011-2022 走看看