zoukankan      html  css  js  c++  java
  • Python学习Day1

    1.配置Notepate++的python环境(在操作系统安装Python的前提下)

    (1) Notepad++ ->"运行"菜单->"运行"按钮

    (2) 在弹出的窗口内输入以下命令:

    cmd /k python "$(FULL_CURRENT_PATH)" & ECHO. & PAUSE & EXIT

    然后点击“保存”,随意取一个名字,比如“RunPython”,为方便,配置一下快捷键(比如 Ctrl + F5),点OK即可。之后运行Python文件只要按配置的快捷键或者在运行菜单上点“RunPython 3.6”即可。

    python:为环境变量配置的执行文件的名称

    2、程序编写

    (1)hello word

    print "hello,world"
    

    (2)输入输出

    代码1:

    a =int(input("A:"))
    b =int(input("B:"))
    c=a/b
    print("sum:",c)

      输出结果:

    A:1
    B:3
    sum: 0.3333333333333333
    

    代码2:

    a =float(input("A:"))
    b =int(input("B:"))
    c=a/b
    print("sum:",c)

    输出结果:

    A:1.3
    B:3
    sum: 0.43333333333333335

    代码3:

    a =float(input("A:"))
    b =3
    c=a/b
    print("sum:",c)

    输出结果:

    A:3.2
    sum: 1.0666666666666667

     段落输出,用三个单引号或者三个双引号。%s为引用变量,后面加%(变量1,变量2)

    代码3:

    a =float(input("A:"))
    b =float(input("B:"))
    c=a/b
    info='''
    -----SUM  C----
    A:%s
    B:%s
    C为A除以B:%s
    ----END----
    '''%(a,b,c)
    print(info)

    输出结果:

    -----SUM  C----
    A:1.0
    B:2.0
    C为A除以B:0.5
    ----END----

    3.if_else语句

    代码1:

    user =input("User:")
    password =input("Password:")
    info='''
    -----User And Password----
    User:%s
    Password:%s
    --------END--------
    '''%(user,password)
    print(info)
    if user=="root" and password=="123" :
        print("####Welcome!####")
    else:
        print("####error user or password####")

    代码输出1:

    -----User And Password----
    User:rot
    Password:123
    --------END--------
    
    ####error user or password####

    代码输出2:

    -----User And Password----
    User:root
    Password:123
    --------END--------
    
    ####Welcome!####

     代码2:

    age =float(input("Age:"))
    if age<0:
        print("Error age")
    elif age>20:
        print("try small!")
    elif age==20:
        print("OK!")
    else:
        print("try large")

    输出结果1:

    Age:-1.2
    Error age

    输出结果2:

    Age:1
    try large

    输出结果3:

    Age:30
    try amall!

    输出结果4:

    Age:20
    OK!
  • 相关阅读:
    emacs 配置
    .Net微服务实践(五)[服务发现]:Consul介绍和环境搭建
    .Net微服务实践(四)[网关]:Ocelot限流熔断、缓存以及负载均衡
    .Net微服务实践(三)[网关]:Ocelot配置路由和请求聚合
    .Net微服务实践(二)[网关]:Ocelot介绍和快速开始
    .Net微服务实践(一)[框架]:微服务框架选型
    研发协同平台持续集成之Jenkins实践
    统一身份认证服务IdentityServer4实践
    DevOps平台架构演进
    ABP框架
  • 原文地址:https://www.cnblogs.com/xue0123/p/6685061.html
Copyright © 2011-2022 走看看