📂
CS-NoteBook
  • Introduction
  • CS144
    • concise introduction to Internet
      • 1.1 Networked Applications
      • 1.2 The 4 Layer Internet
      • 1.3 IP
      • 1.4 A Day in the Life of a Packet
      • 1.5 Principle: Packet Switching
      • 1.6 Principle:Layering
      • 1.7 Principle: Encapsulation
      • 1.8 Byte order and packet formats
      • 1.9 name and addresses:IPv4
      • 1.10 Longest Prefix Match for Link Layer
      • 1.11 Address Resolution Protocol(ARP)
      • 1.12 Summary
    • Transport Layer
      • 2.1 The TCP Service Model
      • 2.2 UDP service model
      • 2.3 ICMP(Internet Control Message Protocol 互联网报文控制协议)
      • 2.4 The End-to-End Principle
      • 2.5 Error Detection:3 schemes (Checksum,CRC and MAC)
      • 2.6 Finite State Machines(有限状态机)
      • 2.7 Flow Control
      • 2.8 Sliding window
      • 2.9 Retransmission Strategies
      • 2.10 TCP Header
      • 2.11 TCP Setup and Teardown
      • 2.12 Recap
    • Package Switching
      • 3.1 The history of Internet
      • 3.2 What is packet switching
      • [3.3 End-to-end delay and Queueing delay
      • 3.4 Playback Buffer(回放缓存区)
  • CS 61C
    • 1.4 C Memory Mangement, Usage
    • 1.5 Intro to Assembly Language, MIPS Intro
    • 1.5 extra bits operation
  • CS 61B
  • CS 61A
    • Function
    • Names
    • The Art of the Function
    • Control
    • Higher-Order Function
    • Recursive Function
    • List
    • Non-Local Assignment
    • Iterators
    • Objects
    • Data Abstraction
    • OOP
    • Inheritance
    • Representations
    • Decomposition
    • Scheme
    • Exceptions
    • Calculator
    • Interpreters
    • Declarative_Programming
    • Table
    • Aggregation
      • More_recursion
    • Databases
    • Distributed_Data
    • Tail Recursion
    • Exercises
      • lab00
      • lab01
      • hw01
      • tree Recursion example -- give Change
  • The Web DevelopMent Bootcamp
    • html5
    • css
    • bootstrap3
    • bootstrap4
    • javascript expression
    • javascript function
Powered by GitBook
On this page

Was this helpful?

  1. CS 61A
  2. Exercises

lab01

Previouslab00Nexthw01

Last updated 4 years ago

Was this helpful?

python3 -i  // 在交互式运行Python文件时对其进行编辑
python3 -m doctest  // 文档测试
>>> positive = 28
>>> while positive: # If this loops forever, just type Infinite Loop
...    print("positive?")
...    positive -= 3
  • 无限循环

    • 只有 0、None、False 为假值

  • x or y

    • x 为真: x

    • x 为假: y

  • x and y

    • x 为真: y

    • x 为假: x

调试技巧

  • 使用print语句

    • 短期调试

  • 长期调试

    • 使用全局 debug 变量

      ```python

      debug = True

    def foo(n): i = 0 while i < n: i += func(i) if debug: print('DEBUG: i is', i)

    ```

    • 只要我们想进行一些调试,就可以将全局debug变量设置 为True

    • (这样的变量称为“标志”)

  • 交互式调试

    • python -i file.py

  • 使用assert语句

    • assert isinstance(x, int), "The input to double(x) must be an integer"

    • assert语句的一个主要优点是它们不仅仅是调试工具,您可以将它们永久保留在代码中

    • 代码崩溃通常比产生不正确的结果要好

    • 并且在代码中声明内容会使代码更容易崩溃

  • PythonTutor调试

    • python ok -q <question name> --trace

Debugging
pythontutor