Yesterday’s lesson focused on the notion of recipes and the notion of computation,namely telling us why and how to learn programming.
Today Prof. Eric Grimson shows us the expressions ,that are formed of operators and operands and three types of algorithm : branching,conditionals,iteration.
All of the structure have their basics .
There is no print unless explicting.
code examples:
str(3)+‘ab'
>>>'3ab'
str(4) < 3
>>>True
compare a string and a number,the result accords to the ASCII.
There is a operator precedence,making * more prior to be computated than +.
paren(s) 括号
variable 变量
comment(s) 注释
assignment statement 赋值声明(it’s not like a box that contains values ,it’s a link to the value)
x=15
y=23
z=x
(z指向的是15这个值,和x指向一样,而非z指向x)
The type is dynamic
x=3>>x=‘abc’
the type has changed from int to string
(we should form a style:don’t chage types arbitrarily)
(make the name of variable sense)
statement : legal commands that python can interpret
(遇到不能直接理解的先记忆,等以后慢慢加深其他知识与这个知识点的联系)
The above is straight-line program ,the following shows the branching programs.
FORMAT:
if <x==y> :
x=x+1
y=y-1
else :
x=x-2
y=y+2
Iteration or loops:
while (x<y):
blocks of instructions
next instruction
注意缩进(identation)表示语句范围,冒号(colon)表示语句开始。
when designing recipe ,try and have a specific test case for each possible path through the code to see if there’s some bugs.
Map problems into the most efficient class to do the computation.
`