zoukankan      html  css  js  c++  java
  • L001-老男孩教育-Python13期VIP视频-19节-pbb

    L001-老男孩教育-Python13VIP视频-19-pbb

     

     

     

     

     

     

     

    Windows上安装 Python3开发环境

    下载:www.python.org >选择Downloads>All releases- python3.5.2

    设置环境变量:编辑>系统变量Path>在最后加入 ;D:softwarePython35

     

     

    这里要把python.exe重命名为python3.exe

     

     

     

    #推荐在脚本里这样写命令

     

    #下面写法也可以,但是不推荐。

     

     

    更换python解释版本

     

     

    #打印用户输入

     

     

    pycharm

    ctrl+d 复制一行

     

     

    #格式化字符串
    name =
    input("input your name:")
    age =
    int(input("input your age:"))  #将接受到的字符串强制转换成数字
    job = input("input your job:")

    print("name is:",name)
    print("age is:",age)
    print("job is:",job)

    msg =
    '''
    Information of user %s:
    --------------------
    name:   %s
    age:    %d
    job:    %s
    -------End----------
    '''
    %(name,name,age,job)     #%s字符串占位符,%d数字整数占位符,%f数字小数占位符。

    print(msg)

     

     

     

    #不明文显示密码。这一段在pycharm里不好用,但是可以在Linux里正常执行。

     

     

    #Linux下执行

    import os
    os.system(
    'df')
    os.mkdir(
    'yourDir')
    cmd_res = os.popen(
    "df -h").read()  #df -h命令的输出保存到cmd_res

     

     

    #观察python的全局变量

    >>> import sys

    >>> print(sys.path)

    ['', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages']

    >>> 

    [root@bolin ~]# cd /usr/local/lib/python2.7/site-packages  

    [root@bolin site-packages]# ls         #将常用导入的包就放到这个目录里

    READMEtab.py

     

     

     

     

    #登录密码v1

    user = 'alex'
    passwd = 'alex3714'

    username = input("username:")
    password =
    input("pawwsord:")

    if user == username:
       
    print("username is correct...")
       
    if password == passwd:
           
    print("Welcome login...")
       
    else:
           
    print("password is invalid...")
    else:
       
    print("连用户名都没蒙对!滚出!!!")

     

     

    #登录密码v2

    user = 'alex'
    passwd = 'alex3714'

    username = input("username:")
    password =
    input("pawwsord:")

    if user == username and passwd == password:
       
    print("Welcome login")
    else:
       
    print("Invalid username or password.")

     

    pycharm

    缩进:选中 - tab

    往回缩进:选中 - shift+tab

     

    #猜年龄游戏
    age =
    22
    counter = 0
    for i in range(10):
       
    print('------------->counter:',counter)
       
    if counter < 3 :
            guess_num =
    int(input("input your guess num:"))
           
    if guess_num == age:
               
    print("Congratulations!you got it.")
               
    break #不往后走了,跳出整个loop
           
    elif guess_num > age:
               
    print("Think smaller!")
           
    else:
               
    print("Think Big...")
       
    else:
           
    #print("too many attempts...bye")
            #break
            
    continue_confirm = input("Do you want to continue because you are stupid?")
           
    if continue_confirm == 'y' :
                counter =
    0
               
    continue
            else
    :
               
    print("bye")
               
    break
       
    counter += 1
     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     





  • 相关阅读:
    linux系统调优工具
    搭建ceph分布式文件系统
    ansible管理windows主机
    jenkins结合ansible发布
    Linux系统安全配置
    tomcat 的安全配置预防后台被攻击
    【9】添加主页日志列表展示
    【8】添加新建/编辑博客逻辑
    【7】使用css/js/html模板来实现一个注册、登录和管理的功能
    Ubuntu下给Sublime Text 3添加用python3运行文件
  • 原文地址:https://www.cnblogs.com/bolinzhihua/p/60ef8da1416d86238f363082f2cbe866.html
Copyright © 2011-2022 走看看