WEEK1-4: from L1(intro) to L7(debegging)

6.00.1x Introduction to Computer Science and Programming Using Python (EDX)

WEEK1-4笔记: from L1(intro) to L7(debegging)


WEEK1-LECTURE1-Introduction to Computer Science

1. An Algorithm VS a Program: An algorithm is a conceptual idea, a program is a concrete instantiation of an algorithm.

2. A computational mode of thinking means that everything can be viewed as a math problem involving numbers and formulas. 

3. The two things every computer can do are: Perform calculations , Remember the results 

4. Declarative knowledge refers to statements of fact. Imperative knowledge refers to 'how to' methods.

5. A fixed program computer VS a stored program computer

6. A program counter points the computer to the next instruction to execute in the program.

7. The computer executes the instructions mostly in a linear sequence, except sometimes it jumps to a different place in the sequence. 

8. Syntax – which strings of characters and symbols are well-­‐formed; Static semantics – which syntactically valid strings have a meaning; Semantics – what is the meaning associated with a syntactically correct string of symbols with no static semantic errors


WEEK1-LECTURE2-Core Elements of Programs

1. Program (or script) is a sequence of definitions and commandsCommand (or statement) instructs interpreter to do something
2. Each object has a type that defines the kinds of things programs can do to it; Objects and operators can be combined to form expressions, each of which denotes an object of some type

2.1 Scalar objects: int, float, bool
1) Operators on ints and floats: +, -, *, /, //, %, **; Comparison operators on ints and floats: >, >=, <, <=, ==, != (Any string is always bigger than any int. )
2) Operators on bools: and, or, not
2.2 Non-scalar objects: str

>>> 3 * 'a'
'aaa'
>>> 'abc'[0] #indexing
'a'
>>> 'abc'[-1]
'c'
>>> 'abc'[1:3] #slicing
'bc'

3. The Python 'None' keyword: In Python, the keyword None is frequently used to represent the absence of a value. None is the only value in Python of type NoneType.
4. The Python 'in' operator: element in coll, element not in coll = not (element in coll)
5. Advanced String Slicing

>>> s = 'Python is Fun!'
>>> s[1:12:2] #s[i:j:k] This gives a slice of the string s from index i to index j-1, with step size k.
'yhni u'
>>> s[1:12:3]
'yoiF'
>>> s[::2]
'Pto sFn'

6. print, raw_input(), type()

7. Branching structures: conditionals e.g., if/elif/else


WEEK2-LECTURE3-Simple Algorithms

1. Looping structures, e.g., while

2. +=, -=, *=, /=; range(start, stop, stepSize)

3. Guess and Check Algorithms: Exhaustive enumeration, Bisection search, Newton-Raphson (for root finding)
(Newton proved a theorem that implies that if a value, call it guess, is an approximation to a root of a polynomial, then guess – p(guess)/p’(guess), where the first derivative of p, is a better approximation. ---from textbook)

4. Decimal number VS Binary number: 302 = 3*10**2 + 0*10**1 + 2*10**0; 10011 = 1*2**4 + 0*2**3 + 0*2**2 + 1*2**1 + 1*2**0 (16 + 2 + 1 = 19);

5. Printing on the same line: add a comma after the print statement


WEEK2-LECTURE4-Functions

1. def, return

2. str.lower(), upper(), isupper(), islower(), capitalize(), swapcase(), index(), find(), replace()


WEEK3-LECTURE5-Recursion(★)

1. The Euclidean algorithm can be used to find the greatest common divisor: If b = 0, then the answer is a; Otherwise, gcd(a, b) is the same as gcd(b, a % b)  example
2. Factorial, Towers of Hanoi, Fibonacci

3. 'divide and conquer' algorithm: solve a hard problem by breaking it into a set of sub-problems

4. Global variables(Use with care!!)

5. import; open(), 'w', 'r', 'a'; read(), readline(), readlines(), write(), writeLines(), close()


WEEK3-LECTURE6-Objects

1. Compound data types: tuples, lists(mutable), dictionaries(mutable)

2. is; 

3. list.sort(), insert(), remove(), append(), pop(), count(), extend(), reverse(); clone

4. str.rfind(), rindex(), rstrip(), split()

5. (dictionaries).has_key(), values(), keys(), get()


WEEK4-LECTURE7-Debugging

1. Black-box testing is a method of software testing that tests the functionality of an application. Recall from the lecture that a way to think about black-box testing is to look at both: The possible paths through the specification. The possible boundary cases.

2. Glass-box test suite is path-complete

3. PS4收获:1. \n 空一行,2. function可以既不print也不return




主要就是PPT,如果期末考试前觉得还不错的话,期末考试前的笔记也这样。。



/* 全局样式 */ body { font-family: Arial, sans-serif; font-size: 16px; color: #333; margin: 0; } a { color: #333; text-decoration: none; } a:hover { color: #555; } ul, ol { margin-top: 0; margin-bottom: 10px; } ul li, ol li { margin-left: 20px; } /* 头部样式 */ header { color: #fff; padding:0 0 0 0; } .container { max-width: 1660px; margin: 0 auto; padding: 0 20px; } #hero { background-image: url(QMZYWY/images/wy.jpg); background-size: cover; background-position: center; color: #fff; text-align: center; padding: 100px 0; } h1 { margin: 0; font-size: 32px; } nav { display: flex; justify-content: flex-end; } nav ul { list-style: none; margin: 0; padding: 0; display: flex; } nav li { margin-right: 20px; } nav a { color: #fff; text-decoration: none; padding: 5px; border-radius: 5px; transition: background-color 0.2s ease; } nav a:hover { background-color: #555; } /* 英雄介绍样式 */ .hero-intro { background-color: #fff; padding: 40px 0; } .hero-intro-text { margin-bottom: 20px; } .hero-intro-image { text-align: center; } .hero-intro-image img { max-width: 100%; height: auto; } /* 游戏攻略样式 */ .game-strategy { background-color: #f5f5f5; padding: 40px 0; } .game-strategy p { margin-bottom: 20px; } /* 页脚样式 */ footer { background-color: #222; color: #fff; padding: 10px 0; } footer p { margin: 0; text-align: center; } /* 响应式样式 */ @media screen and (max-width: 768px) { .container { padding: 0 10px; } h1 { font-size: 24px; } nav { justify-content: center; } nav li { margin-right: 10px; } .hero-intro { padding: 20px 0; } .hero-intro-text { text-align: center; } .hero-intro-image { margin-top: 20px; } } @media screen and (min-width: 768px) { .hero { background-image: url('QMZYWY/images/wy.jpg'); } }在此代码加入网页背景图片响应式
最新发布
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值