Title | Python - Dr. Sopha |
---|---|
Course | Honors Information Systems |
Institution | Arizona State University |
Pages | 2 |
File Size | 43.7 KB |
File Type | |
Total Downloads | 52 |
Total Views | 139 |
Dr. Sopha...
Python -
Created by Guido Van Rossum in 1980s Installer package is called IDLE – an interpreter Good at managing data Cross platform language (portable language) Interpreter (compiler) o Turns the code into something the computer can understand
Math Operators +, -, *, /, // (integer division), % (modulus/remainder), **(exponent)
Steps of an Algorithm (1) Actions we take and (2) the order we do them
Variables – a named memory location holding a value - Preferred style: undercase_and_with_underscores = “This is the preferred style” # String message= “I am literally single characters \* strung \* together” # Integer (or “int”) meaning_of_life = 42 # Floating Point (or “float”) pi_to_five = 3.14159
Errors 1. Syntax errors 2. Runtime errors 3. Logic errors a. Program runs but output is unexpected String- text strung together/ an ordered list of characters - Use escape characters to show special meaning (what comes after \ is included) o \\ - adds a backslash character to strings o \ ‘ – adds a single quote to text o \n – new line o \t – adds a tab
Lists – think of as an ordered group of containers - Very first value is at 0, not 1 Functions Print o Print(data) Input o job = input(“What is your job? ”) o print(“Hey! “ + job + “ sounds like fun!”) use in conjunction with variable - to add numbers, make sure they are temporarily ints, strings will just push numbers together
Random o random.randint(x,y)
Conditional Statements o if(condition) : statement statement … else: statement statement
elif(condition): #put between if and else when multiple conditions occur statement statement Repetition Logic counter controlled repetition – a variable controls the number of times a set of statements will execute sentinel controlled repetition (indefinite repetition) – a special value indicates the “end of data entry” Ex: x=1 while(condition): statement statement x=x+1 #otherwise will be an infinite loop of x = 1 for soda in pepsi_co: print(“Current Soda:”, soda)...