The second lesson:Operators and operands; statements; branching, conditionals, and iteration

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.
`

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

可可卷

不要看到我~~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值