zoukankan      html  css  js  c++  java
  • 第一天Python

    断断续续和反复了几次,今天开始老实的写笔记和画流程图:

    一、python格式:

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-

    二、基本的输入框和打印:

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    print("Hello world!")
    
    name = input("Name:")
    age = input("Age:")
    job = input("Job")
    
    info1 = """
    ==================== info1 of %s ==================
    name:%s
    age:%s
    job:%s
    """ % (name,name,age,job)
    
    info2 = """
    ==================== info2 of {Name} ==================
    name:{Name}
    age:{Age}
    job:{Job}
    """.format(Name=name,Age=age,Job=job)
    
    info3 = """
    ==================== info3 of {0} ==================
    name:{0}
    age:{1}
    job:{2}
    """.format(name,age,job)
    
    print(info1,info2,info3)
    基本的输入框和打印

    三、if判断语句:

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    import getpass  #只能在Linux下使用
    
    name = "jack"
    passwd = "jack123"
    
    user = input("Please input your name:")
    #password = input("Please input your passwd:")
    password = getpass.getpass("Please input your passwd:")
    
    if user == name and passwd == password:
        print("Welcome %s" % user)
    else:
        print("get out")
    if判断语句

    四、while循环:

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    # count = 0
    #
    # while count <3:
    #     num = int(input("Please input num:"))
    #     if num == 22:
    #         print("your are rigth")
    #         break
    #     elif num > 22:
    #         print("bigger")
    #     else:
    #         print("smaller")
    #     count = count + 1
    # else:
    #     print("You have tried too many times..")
    
    
    count = 0
    while count <3 :
        num = int(input("Please input num:"))
        if num == 22:
            print("your are rigth")
            break1
        elif num > 22:
            print("bigger")
        else:
            print("smaller")
        count = count + 1
    
        if count ==3:
            confirm = input("Do you want to continue...")
            if confirm != "n":
                count = 0
    While循环使用

    五、for循环

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    #for循环
    for i in range(10):
        print(i)
    
    #for循环,打印奇数
    for i in range(1,10,2):  #三个参数:[开始、结束)步长
        print(i)
    
    #for循环,打印偶数
    for i in range(0,10,2):
        print(i)
    
    #九九乘法表
    for i in range(1,10):
        for j in range(1,10):
            if j <= i:
                print(j,"*",i,"=",i*j)
    for循环语句
  • 相关阅读:
    Theano入门笔记1:Theano中的Graph Structure
    [译博文]CUDA是什么
    一天一经典Efficient Estimation of Word Representations in Vector Space
    Generating a Random Sample from discrete probability distribution
    关于representation的理解
    git代码管理——克隆项目到本地仓库及上传本地项目到仓库
    yum管理——linux字符界面安装图形化及两种界面的切换(3)
    yum管理——yum常用配置(2)
    yum管理——搭建iso镜像私有yum源仓库(1)
    apche编译安装
  • 原文地址:https://www.cnblogs.com/zheng-weimin/p/9016772.html
Copyright © 2011-2022 走看看