MIT 6.00.01X 计算机科学和Python编程导论 week1

词汇:

armamentarium设备iteration迭代
data structure数据结构recursion 递归
module 模块modularization模块化
algorithm算法algorithmically算法
abstraction 抽象sorting排序
token令牌sort种类
stitch together凝聚,结合fundamentally从根本上
standard classes标准类perform执行
storage存储built-in operations内置(嵌入式)操作
figure out估计,算出abstractv.提取,抽象
encapsulate封装assume假设
crucial至关重要的despite尽管
encryption scheme加密方案philosophical哲学的
declarative 声明的parallel并行的
imperative 必要的(an) integer 整数
4 times 44的4次方x divided by gx/g
execute执行stick in陷入…
square root平方根quadratic root平方根
vacuum tube真空管relays继电器
panicking恐慌nuance细微差别
sophisticated复杂的Comments注释
Branching programs分支程序conditional条件
indentation缩进administrivia信件,新闻
prior优先的ramp 斜坡
curriculum课程sophomore大二
justifiable 无可非议的tackle 处理
competence能力nasty令人不愉快
intimidate  恐吓tactical  策略的
derogatory贬低的insulting  侮辱
scratch  划,绞尽脑汁scratch  抄袭
sidebar 工具条,侧栏recitation  背诵
quiz测试,询问sensitive敏感的
lethal致命的weed杂草
psychiatric神经病plausible似是而非
gruel泡饭,劳累thrill紧张
mandatory命令,强制的draconian严厉的
ironically讽刺的grab  夺取
swing  摇摆annotation注释
spur  鼓励,刺激preamble  前言
instinct本能highfalutin  傲慢的
artifact 手工艺品mechanism  原理
imperative  必要的assertion  断言
axiom  公理heck  见鬼
deduce 推论recipe  食谱,方法
capture  捕获arithmetic  算法
flavor风味diagram  图解
configure  安装component  组成
stack  堆栈neat  整洁的
emulate  仿真spit  唾液
interpret  解释intrigue  阴谋
analogy  类比stiff  僵硬的
yolk  蛋黄nominee  候选人
tease  取消arbitrary  任意的
progenitor  祖先,起源semicolon  分号
dimension 方面,维度trade-off 权衡,交易
matrix  矩阵vector  矢量
semantics语义atrocious  残暴的
worrisome 令人烦恼的propagate  传播
taxonomy  分类学relevant  相关的
merge合并sucker 傻瓜
belt 带,腰带 地带deliberate 商讨
dive 潜水dynamic 动态
nitty-gritty 事实真相hash mark 哈希标记
nuts and bolts 螺母和螺栓precondition 前提
operator 操作者intuition 直觉
operand 操作数brussels sprout 抱子甘蓝
branch lousy 糟糕
conditional 有条件的suffix 后缀
iteration 迭代module 
atomic 原子literally 按照字面
variation 变动motivation 动机,意志
nuance 细微差别interior室内
essential 必要odd 奇数
evaluate 评估colon 冒号
explicit 明确的brace 支撑
replica 复制品nest 
concatenate 串联tentative 试验
bribe 贿赂faculty 学院
paren 括号inherent 固有
spectrum 光谱,范围preface 前言
fudge 蒙混garbled 乱码
lexicographic 字典recursion 递归
discipline 学科procedure 程序
remainder 余数purple 紫色
precedence 优先权clause 条款
exponentiation 幂,乘方indentation 缩进
parentheses 括号awfully 非常
mutation 突变,变动  


Lecture1 计算机科学简介


Turing halting problem 图灵停机问题

无解的程序,输入任何信息,能判断输入的编码是否会结束并给出答案。

计算机做了两件事:计算 和 记录结果

steps 1+2+3 = an algorithm
1)sequence of simple steps. (A checklist)
2)flow of control process that specifies when each step is executed. (A flow of control)
3)a means of determing when to stop. (A thing)


计算机有以下三部分构成:

内存(存储程序和数据) 
控制单元(对已执行的命令计数) 
ALU--Arithmetic Logic Unit 算术逻辑单元算术逻辑单元(检测特定值的大小是否符合停止或跳转程序的条件) 

计算就是有顺序会终结的指令集,编程就是用组合基本指令,分出控制流,得到结果。

interpreter 解释器

程序计数器指向程序将执行的下一条命令


图灵机的6个原语:左移,右移,扫描scan,读取,写入,stop(do nothing)。

Syntax 语法 - what are legal expression "cat dog boy" (Lots of help. Python comes built-in with syntax checker, find one error each time)
  语法用来描述语言中,什么表述是合法的。---判定一个字串是否合法
语法描述了如何将合法表达式组合在一起

Static semantics 静态语义 -what programs are meaningful, which expression make sense "My desk is Susan"    (Some  help.)
静态语义表示什么程序是有意义的,哪种表达是有意义的。---判定一个字串是否有意义
Full semantics 语义 - what does program mean, what happen when run  
完整语义即程序想达到什么目的,运行程序会产生什么效果。---赋予一个合法的语句意义。
语义描述了我们如何从那些表达式中推导出相关的含义,从而解决我们想解决的问题

形式语义:按照语法把字符串和符号组合在一起无静态语义错误的语句。
这就是我们编写代码的意义所在。 一条合法的表达式有且仅有一种意思。

程序是算法的具体实现,计算思维模式意味着一切都可以看做是一个涉及到数字和公式的数学问题。



Lecture2 编程基础


Low level language---Checker检查器(处理低级代码,确认语法和静态语义正确)---Interpreter解释器(指令序列:按序执行指令)---Output
High level language A (Compiled language编译型语言)---Checker---Compiler---Object code(整体转化为low language)---Interpreter---Output
High level language B (Interpreted language解释型语言)---Checker---Interpreter(每一条转化转换成低级指令)---Output

python的IDLE名字为shell,是因为遮住了编译成低水平编程语言的过程。


Scalar objects 标量对象 (不可分割)---int,float,bool

查询对象类型 type(object)

一般expressions表达式的语法 <object><operator操作符><object>
整数型的除法:结果是去掉余数后的quotient商 ,向下取整(Python3中变为float) >>>3/2 1
求remainder余数 %
平方、乘方 ** i raised to the power of j

Operator precedence 优先运行
> < >= <= == != 返回True False
<> 等同于 != 目的是为了和C语言保持consistency一致性,但过时,尽量不用
>> << 二进制移位运算符
a and b
a or b
not a

Tpye conversion(type casting)类型转换 float(3)---3.0 int(3.9)---3 保留整数部分
None(only value in Python of type--"None Type") used to represent the absence of a value

boolean运算优先级 : Parentheses括号>not>and>or

Question:为什么10/3会变成3.33333333335  2.2*3.0=6.60000000000005最后一位5是怎么来的?
Answer:For the last problem (10), typing the expression into your Python interpreter may give a result that is not exact. For example, 6.6000000000000005 instead of 6.6. This is because computers have difficulty storing fractions小数 exactly in binary. 这是因为计算机难以精确的用二进制存储小数造成的。So when performing calculations, numbers first get converted to binary 开始执行时,将十进制转换为二进制,then the calculation is performed and the result converted back into decimal计算后将二进制转换为十进制. However, fractions cannot be stored exactly in binary 小数不能完全存储在二进制(for example, there is no way to store 0.33333 repeating exactly) so we introduce these small rounding errors that propagate传播 until the final answer.


5*2 == 5.0*2.0 10 == 10.0 True ==仅判断的是数值或布尔型是否相等,而不考虑其数值的类型
即同样的数值 整数 == 浮点数

round() 四舍五入
通过help(round)查阅 得 round(number[,ndigits]) ->number
意思就是通过调用round函数,将number四舍五入为精确到小数点后ndigits位的数,默认为0(即默认返回整数)。
round(1.5)返回2 round(2.5)返回2 注意当数在中间的时候返回到最近的偶数 round(2.51)返回3
注:round (bool) 返回0或1。

>>>a = 3 赋值assignment
>>>a + 2.0 返回5.0,但此时a依然为3
>>>a == 5.0 返回False
>>>a 返回3,==只作判断,不会赋值

>>>b = 10
>>>c = b > 9
=是赋值,意思是将等号右边的值赋给等号左边的变量,同四则运算,先计算b>9,再把值给c

一个容易出bug的地方:更新一个变量的值,并不会将用到这个变量的其他变量的值一起更新,因为其他变量的值在之前就储存好了。

Non-scalar objects 非标量对象 (可访问其内部duixiang)


operator overload 操作符重载 : 同样的操作符,针对不同对象,做不同的操作
>>>'a' + 213 error
>>>‘a’ + str(123) 将数123转化为字符串'123',再与‘a’拼接


len() 查询字符串长度

Indexing索引
>>>'abc'[0] 返回‘a’ 'abc'[3] 返回error ‘abc'[-1]返回'c' ‘abc'[-3]返回error
索引 的长度(范围)为[-len(),len()-1]

Slicing切片
string[start:end:step]
>>>'abc'[1:100] 返回'bc'
>>>'abcd'[1:2] 返回'b'


in 和 not in test for membership (string,list,tuple,dictionary)
>>>str1 = 'world'
>>>'orl' in str1 返回True
>>>str[:-1] 返回'worl' -1→d,相当于[0:4]

print() 打印
input() raw_input()
()中可以写string提示输入什么内容
所有获取的输入当做string,所以如果需要输入一个数字,需要转换他的类型 weight = float (input('>>>Your weight:'))


Sets of programming 程序集: branching 分支, conditional 条件 and iteration 迭代


条件语句 基于布尔值测试结果,测试为True 则执行真值块,测试为False 则执行假值块(可选)

if : (必有 唯一)

elif: (可选 多个)

else: (可选 唯一)

一条语句只执行一次


temp = ‘32’
if temp > 65:
print('Hot')
返回 Hot 即 '32' > 65 为True。原因:
在Python2中,数字型对象(int/float/long/complex等) < 其他非数字型对象
如果两个都是非数字型的对象,则按照类型名的顺序进行比较。
eg:dict < str {} < 'abc' ‘abc' > [1,2] 'abc' < (1,2)
在Pytonn3中,不再允许不同类型的object进行比较

常数时间(constant time) 即程序运行时间仅取决于程序长度

Problem11
两个变量A,B,可以是字符串或数字,要求A,B其中一个是字符串则打印'string involved'.
这道题首先不知道A,B的类型,所以需要type()函数确认;
判断是否为字符串,应该用 ==str 判断,而不应该用 is str 或 is not str 判断。(不能写成not is 和 string)
>>>'aaa' is not str 返回True
这道题正确的写法为 if type(A) == str or type(B) == str: print('string involved')
不应该写成 if type(A) or type(B) == str,因为==的执行优先权高于or,且or左侧的type(A)不符合语法。
还有一种正确的写法 if isinstance(A,str) or isinstance(B,str) 利用isinstance()函数


---------------------------------------------------------------------------------------------------------------------------------

声明:第一次写blog,自学用,引用了 leelovelin、s_ywx、thundercaller、chucksonwheel、thundercaller、pivilion几位前   辈的部分内容,如有侵犯版权之嫌请留言,这方面不很懂

--------------------------------------------------------------------------------------














  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值