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!

 

posted @ 2017-04-09 16:06  正在努力的BOY  阅读(196)  评论(0编辑  收藏  举报