Unit 3: Programming with Python
python prompt
>>>is a symbol that begins the program, standing 'ready to receive' your instructions. This prompt basically says "ready"
Compiler
A program that translates code in a high-level language (such as Python) and converts it into binary machine language.
Code
A way of conveying information as symbols. Symbols that have meaning when read in a predefined way
interactive mode
A way of using the Python interpreter by typing commands and expressions at the prompt.
Natural Language
Any one of the languages that people speak that evolved naturally. Ambiguous; many different meanings for the same word
Program's 3 parts
Input - entering data into the computer processing - data being manipulated to do what is intended output - a provided result in some format
Assembly Language
It abstracts the information provided by a high level language (Python for example) into a middle level language which will then convert it to machine language
unary operator
an operator that has only one operand and applies only to the one number after it; example => -3 (negation modulus)
binary operator
an operator that has two operands and refers to them both (2 + 2)
object-oriented programming
designing a program by discovering objects, their properties, and their relationships
sequential
doing steps after one after the other in the order they are listed. for example, not trying to call a function before creating a function
reassigning variables
make it equal to the new value example: teacher = Mr. Morton teacher = Ms Del-Sette
semantics
meaning of statement, what happens when the statement is executed. It's exact. English isn't. "That's cool" can mean different things.
key words
reserved words that have a special meaning in python and can not be used as variables example: if, while, for, class
% modulus
returns the remainder only ie 17 % 3 = 2 (15, r 2)
Syntax
the structure, rules, and correct format for writing a programming language
data types
three main data types in Python; strings integers and floats, booleans, dictionaries, sequences, sets
graphic shapes
variable = Circle(radius) variable.set_position(x, y) variable.set_color(color.black) add(variable)
graphics text
variable = Text("fill") variable.set_position(x, y) - refers to bottom left variable.set_color(color.black) variable.set_font("50pt Arial") add(variable)
Python Rectangles
variableName = Rectangle(width, height) variable.set_color(color.red) variable.set_position(x, y) - refers to top left corner add(variable)
input function when an integer is required
when you are requiring the user to enter a whole number it requires "int" added to the input statement. example: number = int(input("Enter a number: "))
Python Canvas
* Coordinate System * Top Left (0, 0), Bottom Right (400, 400) get_width() - get canvas width get_height() - get canvas height
Programs are developed to:
* Express Creativity * Satisfy personal curiosity * Create new knowledge * Satisfy a common need (Netflix)
parts of a variable
1. the name, 2. its data type - int, float, str, 3. its value
Data type determines
1. the possible values for that variable 2. operation that can be done with the value 3. meaning of the data 4. the way value of that type get stored
Python Facts
1.Created in late 1980's by Guido Van Rossum 2.named from Monty Python's Flying Circus Tv Show 3. It is open-sourced 4. One of the official languages of Google and Mozilla Firefox
Order of Operations
PEMDAS
script mode
allows us to store python script source code in a file with the .py extension and then use the interpreter to execute the contents of the source file
Programming language
Provides the standards, syntax, statements, and instructions for writing a language that our computer can understand. Not ambiguous - has one meaning
Open Source
Software that is created for free use by everyone
Machine Language
The language made up of binary-coded instructions that is used directly by the computer. Low level language
variable (Identifiers)
What we work with in python, its a name we assign a value to
assignment statement
allows us to assign and update a value to a variable. Has a name, an equal sign, and a value.
Pseudocode
Writing out in natural language what you want your code to do
prototype
a drawing of what your code should look like
Callback function
a function that is triggered by another function in response to some event. We bind a function to the mouse click event then pass the information to that function. Ie) def click(x, y) #action to take place #when mouse clicked add_mouse_click_handler(click)
input function
a function that prints a prompt asking for text from the user example: name = input("What is your name: " ) print (name)
Algorithm
a step-by-step procedure for solving a problem, a combination of algorithms make up a program
mouse click events
allow user interaction in our program