Python 002 day

课堂笔记和作业:

A

print("the number game")

temp=input("guess my number now:")

guess=int(temp)

if guess==3:

  print("yes.")

else:

  print("no,it is 3.")

print("game over.")

B

if int(input("guess the number:"))==3:

  print("yes.")

else:

  print("no,it is 3.\ngame over.")

课后自由尝试:

A

x=int(input("the number is:"))

if x==2:

  print("yes")

else:

  print("no")

B

x=input("the number is:")

x=int(x)

if x==2:

  print ("yes")

else:

  print("no")

C

x=input("the number is:")

x=int(input)

if x==2:

  print ("yes")

else:

  print("no")

运行错误,提示input部分出错,不能在此处使用BIF。

D

x=input("the number is:")

x=int(input("the number is"))

if x==2:

  print("yes")

else:

  print("no,")

input内容在运行中出现了两次。

知识点记录:

01

Ctrl+N:新建窗口

Tab键功能:缩进;提示功能(猜测没有写完的部分)

Ctrl+S:保存

F5/RUN>>>RUN MODULE:运行

02

if;else条件分支:

if+条件+:

==:判断是否相等

=:赋值(右边的值赋予左边,标识符只有赋值了才不会导致出错)

input:python的内置函数(bif:built-in functions,为方便快速编写脚本)>>>将参数显示到屏幕上,接收用户输入数据

temp:字符串变量(和input不同,temp和guess是自定义函数,需要定义后才能使用)

int:整数

float:小数

03

怎么知道python里有多少个BIF?

a.打开shell

b.输入

>>>dir(__builtins__)

c.出现的列表中纯小写的是BIF

(P.S.3中总共有68个)

怎么知道BIF的功能?

a.

>>>help(输入bif的名字)

e.g.

>>>help(input)

04

在python中,大小写和缩进非常重要,一定要注意。

在正确的位置输入“:”后IDLE会自动在下一行中缩进。

05

python和c语言不同,不允许if条件赋值(用=),运行失败标注出错。

06

拼接字符串:"i"+"am"+"python">>>"iampython"

课后附加练习:

01

x=input("excuse me,what is your name?\n")

print("hello,"+x+"!i am python.")

02

if 1<=int(input("please write a number between 1 and 100:\"))<=100:

  print("thank you!well done!!")

else:

  print("no......")

x=input("please write a number between 1 and 100:\n")

x=int(x)

if 1<=x<=100:

  print("thank you!well done!!")

else:

  print("no.....")

03尝试前两个结合:

x=input("hello,you are?\n")

if 1<=int(input("ok,"+x+",please help me write a number between 1 and 100:\"))<=100:

  print("thank you!"+x+"!well done!!")

else:

  print("no......")

其他资料:

Pycharm:

是一种Python IDE(Integrated development Environment:集成开发环境),在Python开发时可以协助提高效率。

编码补全,代码折叠,分割窗口....

Anaconda:

是一个开源的Python发行版本,包含了大量的科学包(包括Conda,Python及工具包:numpy、pandas....),因此下载文件较大,还有一个较小发行版考虑——Miniconda(包括Conda、Python)。

conda:开源包,环境管理器,可用于在同一个机器上安装不同版本的软件包和依赖,并在不同环境下切换。

Python缺少系列包,需要安装pip导入这些包才可以完成一些对应的运算(3.5内有get-pip.py,不需要再安装一次了)。

猜你喜欢

转载自www.cnblogs.com/JET-D/p/12791477.html