快速回顧
1. 命令行運行python
python3 foo.py
,運行文件python3 -i foo.py
,運行python腳本,並打開一個交互式會話python3 -m doctest foo.py
,運行doctest
2. 命令行運行ok
python3 ok -q <specified function>
, 運行指定函數python3 ok -v
, 模式不顯示已通過的樣例,-v可以全部顯示print("DEBUG:", x)
, 調試打印功能
主題
1. 除法
- True Division: / (decimal division),常規除法
- Floor Division: // (integer division),整除
- Modulo: % (remainder),取模
2. 函數及其調用
To evaluate a function call:
- Evaluate the operator, and then the operands (from left to right).
- Apply the operator to the operands (the values of the operands).
return and print介紹
3. Control
- 布爾運算符 and,or,not
- 短路特性 and,or
- if 語句
- while 循環
4. 錯誤信息
必答題 required questions
what would python display
Q1: WWPD: Control
python ok -q control -u --local
- how_big(),注意
print(' ')
和return ' '
的引號區別。 while positive
,while循環內部修改變量positive,但是positive不為0(負數也是True),無限循環。
Q2: WWPD: Veritasiness
python ok -q short-circuit -u --local
- 理解短路特性較容易
Q3: Debugging Quiz!
python ok -q debugging-quiz -u --local
Coding Practice
Q4: Falling Factorial
python ok -q falling --local
caution:print or return
Q5: Sum Digits
python ok -q sum_digits --local
Hint:floor division and modulo
caution:需要返回值
Extra Practice 額外練習
Q6: WWPD: What If?
python ok -q if-statements -u --local
Hint: print (unlike return) does not cause the function to exit!
caution:print(' ')
和return ' '
的引號區別
Q7: Double Eights
python3 ok -q if-statements -u --local
相鄰的兩個8:
return '88' in str(n)