您的位置:首页 > 理论基础

麻省理工学院公开课:计算机科学及编程导论 课堂笔记

2018-01-21 22:30 525 查看
6.00 

lecure1

4000
skill goals:

1. computational thinking

2.read and write code

3.solve problem 

think like a computational scientist

what is computaion?

python:三个维度来看:

high-level or low level language

general or targeted language

编译语言 or 解释语言

语法 syntax: what are legal expression in this language

语义 static semantics: what programs are meaningful

full semantics: what does the program meaning; what happen when running python

data

 numbers

 integer (INT)

floating point

strings

  'abc' 

表达式expression

3**5 次方;3/5=0;3.0/5浮点数;

为一个变量命名 value='eric'  绑定;

lecture 2

data

 value and type

combine in expressions: ooperands and operators 运算符和运算对象

interpreter解释器 : evaluate and print

script 脚本: no print unless explict 除非我们让它这么做

str(3)+'abc' str: 变成字符串

type checking : weak or strong 

4<'3' 没有报错,但是无意义

typing discipline 规范

运算前规定数据类型

9/5=1

9%%5=4

operate precedence操作优先 乘除>加减

when in double ,use parents括号

赋值 assignment 绑定binding 变量  linking to a 值

变量 variable  X=3 used anywhere leghal

类型 is 动态的 X='ABC'  不要反复改变变量的类型

statements 声明 : legal commands that python can interpret

comments 注释 帮助reader理解代码的含义

变量名称的选择 : 评价是否优秀的代码 excluded key words

line programs : run one by one

branching programs : can change the order of instructions based on tests

 : colon冒号 定义指令集/指令集的开始;回车意味着指令集的结束

x=15#把等号左边的值绑定到右边的变量

if (x/2)*2 ==x : #==判断左边的值是否等于右边

 print 'even'

else: print 'odd'

if <some test> :

 block of instructions

else:

 block of instructions

if 可以嵌套

x=15

y=13

z=11

print x,y,z

if x<y:

 if x <z : print 'x is least'

else:print'z is least'

else: print 'y is least'

#is this right?

if x<y and x<z: print 'x is least'# and ;or; not;

elif y<z: print 'y is least'# elif else if 简写

else: print'z is least'

计算复杂度-算法种类

iteration or loops 迭代 或者循环

y=0

x=3

itersLeft=x

while(itersLeft>0): y=y+x

itersLeft=itersLeft-1

#求数的平方

print y

循环内必须有会变化的量

写代码前一定要搞清楚对输入值的期望
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: