COMPSCI 101L Chapter Notes - Chapter 3-5, 6: Deterministic Algorithm, Global Variable, Local Variable
Computer Science
Chapter 3, 4.1-4.3, 5, 6.1-6.4 Reading Notes
Chapter 3
- Important to test your code for a range of inputs
- Also important to test on boundary conditions
- ParseError: they happen when you make an error in the syntax of the problem
o Kind of like grammar mistakes
o Missing parentheses, quotation marks, or commas
- TypeError: they happen when you try to combine two objects that are not compatible
o Ex: when you try to add a string and an integer
- NameError: happens when you have used a variable before it has a value
o Usually a spelling mistake
- ValueError: happens when you pass a parameter to a function and the function is
expecting a certain limitations on the values, and the value passed is not compatible
o When user inputs incorrect function (such as a string when the program is
expecting an integer)
- When debugging, print statements are useful
Chapter 4
- Turtles can be used to draw pictures
- Turtles start out facing East
- An object can have various methods (things it can do) and attributes (properties)
- Import turtle – defines the module turtle, which will allow you to create a Turtle object
and draw with it
- Turtle is a type or class, multiple turtles are all instances of the Turtle type
Chapter 5
- A module is a file containing Python definitions and statements intended for use in other
Python programs
o Ex: turtle
o When you import turtle, you can access a bunch of classes in them
o turtle.screen – in the turtle module, I would like to access the screen class …
o Python Documentation site has a list of all available modules for Python 3
- First thing you need to do when using a module is to import it
- To use something in a module, you should provide the module name and the specific item
joined together with a dot
- We learned about the math and random modules
- Random number generators are based on a deterministic algorithm – predictable and
repeatable
- Pseudo-random – start with a seed value, not truly random
Chapter 6:
- Function is a named sequence of statements that belong together
- Main purpose: help us organize programs into chunks that match how we think about the
solution to the problem.
find more resources at oneclass.com
find more resources at oneclass.com
Document Summary
Important to test your code for a range of inputs. Also important to test on boundary conditions. Parseerror: they happen when you make an error in the syntax of the problem: kind of like grammar mistakes, missing parentheses, quotation marks, or commas. Typeerror: they happen when you try to combine two objects that are not compatible: ex: when you try to add a string and an integer. Nameerror: happens when you have used a variable before it has a value: usually a spelling mistake. Turtles can be used to draw pictures. An object can have various methods (things it can do) and attributes (properties) Import turtle defines the module turtle, which will allow you to create a turtle object and draw with it. Turtle is a type or class, multiple turtles are all instances of the turtle type. A module is a file containing python definitions and statements intended for use in other.