zoukankan      html  css  js  c++  java
  • week_onepython基础 基本语法、流程控制

    金角大王的紫金葫芦,python开发环境介绍链接:
    http://list.youku.com/albumlist/show/id_28961509.html

    # Author:larlly
    python2.x需要字符编码utf-8,才可以支持中文
    # _*_  coding:utf-8 _*_

    # 用户输入
    name3 = input("what is your name : ")

    print ("my name is ",name3 )

    #输入密码时如果想要不可见,就要用getpass模块中的getpass方法

    #加密
    import getpass
    #pwd = getpass.getpass("请输入密码:")
    pwd = input("请输入密码:")
    print(pwd)

    # 模块初识,python的强大之处在于他有非常丰富和强大的标准库和第三方库。

    sys库
    import sys
    print(sys.argv)
    输出
    python 1.py hello world #把执行脚本时传递的参数获取到
    ['1.py','hello','world'] 就是一个列表 [0] [1] [2]

    print(sys.path) #查看python环境变量列表

    os库
    调用系统命令
    import os
    os.system("df -h")

    结合os,sys模块
    import os,sys
    os.system(''.join(sys.argv[1:1])) #把用户输入的参数当作一条命令交给os.system来执行

    打印类型
    print( type(username))

    判断if-else:
    import getpass
    _username = "larlly"
    _password = "123"
    username = input("what is your name: ")

    password = input("qing shu ru mi ma: ")
    #password = getpass.getpass("请输入密码:")
    if _username == username and _password == password:
    print("welcome login" ,username )
    else:
    print("username or password is error !")
    #打印字符串
    print ("his name is %s " %("a"))

    #打印整数
    print ("he is %d years old" %(25))

    #打印浮点数
    print ("his height is %f m" %(1.68))
    #打印浮点数(指定保留小数点位数)
    print ("his height is %.2f m"%(1.69))

    #指定占位符宽度
    print ("name:%10s age:%8d height:%8.2f"%("abc",25,1.69))

    #指定占位符宽度(左对齐)
    print("name:%-10s age:%-8d height:%-8.2f"%("abc",25,1.69))

    #指定占位符(只能用0当占位符)
    print ("name:%-10s age:%08d height:%08.2f"%("abc",25,1.69))

    #科学计数法
    print(format(0.0015,'.2e'))

    #格式化输出(俩种格式)

    name = input("name:")
    age = input("age:")
    job = input("job:")
    salary = input("salary:")


    info = ''' Info of the ''' + name +'''
    Name:''' + name +'''
    Age:''' + age + '''
    Job:''' + job + '''
    Salary:''' + salary + '''
    '''

    """
    info = '''INFO OF THE %s
    NAME:%s
    AGE:%s
    JOB:%s
    SALARY:%s
    ''' % (name,name,age,job,salary)
    """
    print(info)



    #猜测年龄,超过三次就跳出

    count = int(0)
    age = int(25)
    while (count < 3):
    age_guess = int(input("请输入我的年龄: "))
    if age == age_guess:
    print("very good ,your answer is good")
    break
    elif age_guess < age:
    print("your answer can older")
    else:
    print("your answer can younger")
    count +=1
    else:
    print("兄弟,都三次啦@")


    for循环及if-elif-else嵌套
    for i in range(10):
    print("larlly:",i)

    #i小于5跳出本次循环,等于5打印,大于5中断
    for i in range(10):
    if i < 5:
    continue
    print(i)
    elif i == 5:
    print(i)
    else:
    break
    print(i)

    #死循环
    count = 0
    while True:
    print("who is that ?")
    count += 1

    #循环百次
    count = 0
    while count <100:
    print("who is that ?")
    count += 1
    print (count)

    count = 0
    while True:
    print("who is that ?")
    count += 1
    print(count)
    if count == 100:
    print("该中断了")
    break
    
    
  • 相关阅读:
    第03组 Alpha冲刺 总结
    第03组 Alpha冲刺 (6/6)
    第03组 Alpha冲刺 (5/6)
    第03组 Alpha冲刺 (4/6)
    第03组 Alpha冲刺 (3/6)
    第03组 Alpha冲刺 (2/6)
    第03组 Alpha冲刺 (1/6)
    第03组(63) 需求分析报告
    第03组(63) 团队展示
    第09组 Alpha冲刺 总结
  • 原文地址:https://www.cnblogs.com/luoliyu/p/6482990.html
Copyright © 2011-2022 走看看