zoukankan      html  css  js  c++  java
  • python 基础 day1

    版本3.5
    注意事项:每行不能超过80字节 换行用 ''' ''' 
     
    hello.py
    #!/usr/bin/env python       声明解释其类型
    # -*- coding:utf-8 -*-      国际编码支持中文
    # Author:QL                 作者
    
    name = 'QL'                #变量名要让人看懂不能起无意义名称,方便日后查看
    name2 = name               # name2=name 其实是直接赋值name2="QL"
    print(name,name2)          #3.5版本打印加括号
    name = 'lanlan'            # name重新赋值 那么name2=?
    print(name,name2)          #('lanlan','QL') 
     
    t1.py
    #!/usr/bin/env python
    name = input("input your name:")
    age = input("input your age:")
    job = input("input your job:")
    msg ='''
    Information of user %s:
    -----------------------
    Name: %s
    Age : %s             # %d 整数%f 浮点数%s字符
    Job : %s
    ---------end----------
    ''' %(name,name,age,job)
    print(msg)
     
    if.py
    #!/usr/bin/env python
    user = 'QL'
    passwd = '123'              #用引号引起来代表123为字符串,如果不用引号的数字,
                                #就是整数那么password应用int声明是数字 password = int(input())
    username = input("username:")
    password = input("password:")
    if username == user and password == passwd
        print("Welcome login...")
    else:
        print("invalid username or password...")
    t2.py
    #!/usr/bin/env python
     
    import getpass
    username = input("username:")
    password = getpass.getpass("password")#密文输入密码
    print(username,password)
     
    import os
    os.system('df')                       #使用shell命令
    os.mkdir('yourdir')
    cdm_res = os.popen('df -h').read()    #命令输出结果赋值给一个变量
     
    import sys
    print(sys.path)  #查看路径 如果自己写的模块没在显示的路径下就找不到自己写的模块需要添加#'/usr/lib/python2.7/dist-packages' 自己写的模块 

    guess age.py

    age = 27
    counter = 0
    for i in range(10):
        if counter <3:
            guess_num = int(input("input guess num:"))
            if guess_num == age:
                print("You are right!")
                break
            elif guess_num > age:
                print("Think smarller")
            else:
                print("Think big")
        else:
            continue_confirm = input("Do you want to contine:")
            if continue_confirm == 'y':
                counter = 0
                continue 
            else:
                print("bye")
                break
        counter += 1
     
  • 相关阅读:
    数学+高精度 ZOJ 2313 Chinese Girls' Amusement
    最短路(Bellman_Ford) POJ 1860 Currency Exchange
    贪心 Gym 100502E Opening Ceremony
    概率 Gym 100502D Dice Game
    判断 Gym 100502K Train Passengers
    BFS POJ 3278 Catch That Cow
    DFS POJ 2362 Square
    DFS ZOJ 1002/HDOJ 1045 Fire Net
    组合数学(全排列)+DFS CSU 1563 Lexicography
    stack UVA 442 Matrix Chain Multiplication
  • 原文地址:https://www.cnblogs.com/QL8533/p/5482206.html
Copyright © 2011-2022 走看看