Computer Programming Concepts PDF
Document Details
Tags
Summary
This document provides a summary of fundamental computer programming concepts. It covers topics like absolute value, abstraction, and algorithms in a straightforward manner, suitable for introductory computer science courses or self-study.
Full Transcript
Absolute Value: ○ The number itself, ignoring whether it’s - or + Abstraction: ○ Hides the details; gives you less control ○ The title of the recipe, without needing to see the steps ○ The title “go to the bathroom” without needing instructions ○...
Absolute Value: ○ The number itself, ignoring whether it’s - or + Abstraction: ○ Hides the details; gives you less control ○ The title of the recipe, without needing to see the steps ○ The title “go to the bathroom” without needing instructions ○ Like the art, there are almost no details, it’s just one blob ○ Opposite of algorithm ○ In coding, examples include creating functions, variables, etc. - even block-based code is an abstraction (need less skill) Algorithm: ○ The sequence of instructions to solve a problem; The step-by-step details ○ VERY detailed (the steps for “go to the bathroom” and instructions for the recipe) ○ Gives you the most control ○ Opposite of abstraction American Standard Code for Information Interchange (ASCII): ○ Most common character encoding format for text data on computers and internet ○ Very basic text without formatting, or “plain text”, which is automatically created by Notepad.exe, or you can save a Doc or Word file as “text only” ○ Click to check Unicode text values in zyBooks (2.11.4) ○ Click for link to the table Append: ○ To add something Application (App): ○ See program Argument (or Parameter): ○ The item(s) passed to a function in its parentheses ○ Separate multiple arguments with commas ○ Python uses the word argument, some other languages use the word “parameter” ○ Example: import math num = 49 num_sqrt = math.sqrt(num) “num” is the argument inside the function print(num_sqrt) 7.0 Assembler: ○ Programs made to automatically translate assembly language instructions into machine instructions ○ Human-readable processor instructions Assembly [Language Instructions]: ○ A 1940’s language slightly easier for humans to understand that was then translated using an assembler Assignment Statement: ○ Gives a value to a variable ○ Basically any time there’s an equal sign (just one), it’s an assignment statement ○ Left side must be variable name, then equal sign (“PUTS”) the right side’s value into the variable, which can be an expression ○ If the directions say “assign” that means create a variable ○ Examples: my_age = 14 years_of_high_school = 4 graduation_age = my_age + years_of_high_school print(graduation_age) 18 years_til_18 = 18 - my_age print(years_til_18) 4 blended_family_siblings_total = 6 + 2 print(blended_family_siblings_total) 8 Automatic Memory Management (AMM): ○ A way that an OS or program automatically manages the allocation and deallocation of memory so a programmer does not have to write code to perform memory management tasks when writing a program ○ Learn more on techopedia Backwards Compatible: ○ Means that older versions of something can run successfully on newer versions Base: ○ Base 2: Numbers 0, 1 (binary) Each digit’s place is “weighted” by increasing powers of 2 Table 3.10.2 ○ Base 10: Numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Each digit’s place is “weighted” by increasing powers of 10 Table 3.10.1 Basic Input/Output System (BIOS): ○ The first program run when turning on a computer ○ Sets up the computer’s basic peripherals ○ Usually stored at memory location 0 Binary Numbers: ○ 0’s and 1’s ○ Often used in bits for base 2 Bits (or Binary Digits): ○ The smallest unit of data a computer can store (2 slots) ○ Word comes from combo of the words binary digits ○ Ways it can be represented: 0 / 1 (usually) True / False On / Off Yes / No ○ Side Note: A computer can only hold so much. They are usually made to hold 32 or 64 bits for a variable (which limits the size/range of numbers that a variable can hold), but Python does some programming magic and moves memory around so it can hold much larger numbers. So we don’t really have to worry about it, this is just useful info. Bug (or Logic Error): ○ A coding error in a computer program that occurs when the logic is flawed ○ When code does not work as expected ○ An error subtle enough to silently misbehave (no crashing or runtime errors) ○ Got its name when Grace Hopper discovered a moth preventing a Harvard computer from working - they taped it in a log book ○ How to avoid Be knowledgeable in the language Check code periodically, not just at the end (write a few statements at a time) Byte: ○ A sequence (ordered flow) of 8 bits treated as one whole unit (read together) ○ If using base 2, this means that the highest number that can be represented is 255 Cache: ○ The small amount of volatile RAM that may be on a processor’s own chip to give the fastest access ○ It is accessible in one clock tick instead of several ○ Used to maintain a copy of the most-used instructions/data Camel Case: ○ A naming convection that when you name things, separate words by starting every new word (except the first one) with a capital letter instead of an underscore ○ Example: camelCase vs camel_case Case Sensitive: ○ Means uppercase and lowercase letters are seen differently Central Processing Unit (CPU): ○ See processor or microprocessor Circuits: ○ Connections of switches Clock: ○ Measures and governs the rate of speed that a processor’s instructions execute ○ It ticks at a specific frequency ○ It executes about one instruction per clock tick (so millions or billions of instructions per second) ○ Miss Haan is not good at explaining this one - find a video? ○ Examples: 1 MHz (1 million ticks per second) for an inexpensive ($1) processor, like in a microwave or washing machine 1 GHz (1 billion ticks per second) for more expensive ($10-$100) processors, like in a smartphone or computer Code: ○ The textual representation of a program (because for a computer it’s actually all binary numbers, but that’s hard for us to understand) Code Point: ○ The unique number used to represent every possible character using Unicode Compilers: ○ Programs that automatically translate high-level language programs into low-level machine instructions, or executable programs Computational Thinking: ○ Creating a sequence of instructions to solve a problem ○ Helps us work logically through big problems by breaking them down into smaller pieces, looking for patterns, and using the information to come up with a step-by-step solution Computer: ○ Basically a processor interacting with a memory ○ Before the 1940’s and 1950’s it was used in reference to a human that did computations by hand ○ Now includes PC’s (personal computers), laptops, book readers, smart phones, tablets, iPads, and even computing devices embedded in other electronic devices (like medical equipment, automobiles, consumer electronics, and military systems) Concatenate: ○ To join together Container: ○ A programming structure used to hold or organize similar/related values together ○ It contains references to other Python objects, not data ○ See visual aid chart - containers are empty fridges ○ Includes: Set Type Sequence Types Lists Tuples Strings Mapping Types Dictionaries ○ How to decide which container: List: Data has an order (like lines of text on a page) Tuple: Data has an order AND should not change Dictionary: If order is not important and relationships between elements is (such as student names and grades) Core: ○ Each of the several processors contained within one of several billion transistors within an IC Crash: ○ Sudden and accidental end of a program (often due to a runtime error) ○ Abrupt and unintended termination Data Type (or Type): ○ Determines how a value or object can behave ○ The category of information (like labeling something name, date, etc.) ○ What kind of information is going somewhere (and what is allowed) ○ See type() in python pedia ○ Types (See Visual Aid): Boolean Numeric Types Floating-Point Integer ○ Examples: Integers can be added and multiplied Strings can be appended (added, not mathematically) with additional text or concatenated together Debugging: ○ The process of finding and fixing bugs; troubleshooting Identify problem Isolate source of problem Correct problem OR find a workaround Test correction/workaround Decrementing: ○ Decreasing by a set amount over and over again ○ Opposite is incrementing ○ Example with each punch in a video game being -2 health health = 40 punch_value = 2 (why is this not -2? It negates the - below) health = health - punch_value Shortcut: health -= punch_value (also for /=) Disk (or Hard Drive): ○ A storage-type non-volatile hardware that stores files and other data like files, songs, movies, documents, etc. differently than flash ○ How it works: Is non-volatile by aligning magnetic particles in a 0 or 1 spot The disk spins under a head that pulses electricity at just the right times to adjust specific particles Element: ○ An item in a list End-of-Life: ○ When something officially has no more improvements, fixes, or support (even if there are security problems); sunset Error: ○ Can include whitespace in zyBooks (like it expects a space or newline) ○ Kinds of errors: Logic (bug) Runtime Syntax Overflow ○ ○ ○ OverflowError: Overflow occurs when a value is too large to be stored in the memory allocated by the interpreter A standard 32-bit installation of Python… Maximum floating-point value is approximately 1.8x10308 Minimum floating-point value is 2.3x10-308 Error is created when you assign a floating-point value outside of the allowed range Escape Sequence: ○ Two-item sequences that are understood in the IDE as the start of a special character’s instructions The first item, or the backslash (\), tells the interpreter to display (show), exempt (ignore), or create something Based on the second item ○ See the escape sequences in python pedia ○ Can be ignored using a raw string (see r in python pedia) ○ Evaluate: ○ Kinda like DOING the math (you can tell 5 * 5 is supposed to do something) ○ The process of an expression “evaluating” to a value ○ Done in order of operations, called “precedence rules” in programming ○ Example: x = 5 x = x + 1 evaluates to 6 y = x + 1 assigns y with 6 Executable (or Executable Program): ○ A sequence of machine instructions together Execute: ○ Basically, run; run a program Expression: ○ Code that returns a value when evaluated (like 5 * 5 = 25) ○ A combination of items, like variables, literals, operators, and parentheses, that evaluates to a value, like 2 * (x + 1) ○ Often used on the right side of an assignment statement Flash [Storage]: ○ Storage devices that store the 0’s and 1’s in a non-volatile memory rather than disk ○ How it works Tunnels electrons into special circuits on the memory’s chip Removes them with a “flash” of electricity that draws electrons back out Float (or Floating-Point): ○ A data type that is a real number that CAN include a decimal, but does NOT HAVE TO ○ The name refers to the decimal point appearing anywhere (“floating”) in the number ○ See float() in python pedia ○ Watch for OverflowError ○ Only accurate up to 15 decimal places, 16th place can be inaccurate ○ By default, most programming languages output at least 5 digits after the decimal ○ In general, floating-points should be used to represent quantities that are measured, such as distances, temperatures, volumes, and weights ○ Takes up more memory than an integer ○ Python automatically ignores extra zeros present at the number’s end ○ Examples: 1.0, -898.450, 8949.250, 5.5, 0.25, -13.79 ○ Click for a link about floating-point types ○ Floating Point Literal: A number written with the fractional part, even if that fraction is zero Example: 1.0, 0.0, 99.0 Format Specification: ○ A rule for how something should be formatted ○ Putting it inside a replacement field lets the value’s formatting in the string be customized ○ See more details in python pedia ○ How-to: Formatted: { what : how } What: an expression to be evaluated, even just a variable or a value How: special characters that say how it should look Formatted String Literal (f-string): ○ Used to format strings (see f-string in python pedia) ○ With a replacement field: Allows a programmer to output (print) a string with a replacement field (placeholder) that is evaluated (filled in or understood) as the program executes ○ With a formatting specifier: Allows the programmer to output a number with a minimum/maximum number of decimal places ○ Can combine several data types using this, but the final result will always end up a string ○ What: Used to format strings when printed (change how you want them to look) A thing used to adjust how a string is going to look when printed ○ Why: Format a string mixed with variables or other data types and control the spacing If you include replacement fields (placeholders), it allows a programmer to output (print) a string with a variety of data types that are evaluated (filled in) as the print statement executes Function: ○ A list of statements that can be executed simply by “calling” (referring to) the function’s name ○ Like a recipe title - you don’t have to list the ingredients and steps every time ○ The recipe steps are the algorithm, calling it is an abstraction ○ Similar to a variable that you create a name to hold information ○ Read arguments (usually in parentheses after function name, separated by commas) ○ Example: import math num = 49 num_sqrt = math.sqrt(num) “num” is the argument inside the function print(num_sqrt) 7.0 ○ Function Call: Writing a function’s name to use it The process of invoking a function Form of abstraction Garbage Collection (GC): ○ A form of AMM built into many programming languages ○ The language will have one or more “garbage collectors” (GC engines) that automatically free up memory space that has been allocated to objects no longer needed by the program ○ Learn more on techtarget Gigabyte: ○ A billion bytes Good (or Best) Practices: ○ Don’t affect the functionality of a program, but rather the experience for the humans who will be reading and maintaining the code ○ Examples: Proper naming conventions Lowercase letters with underscores When dealing with scientific or engineering names, add the unit of measure (not just temperature, but temperature_celcius) Only use abbreviations if widely understood (like tv or app) Whitespace Hitting tab (and enter) for every element (item) in a dictionary To create a new block, pick a consistent indent level can be either 4 spaces (columns) or 1 tab per level Refactoring Comments explaining code Iteration When you open something, close it right away Incremental development Math/Expressions-related: Always use parentheses to make order of evaluation explicit, as it is top of the precedence rules and helps prevent bugs Use a single space around all operators for readability (except for an unary) Floats should not be compared using the equality operators, due to the imprecise representation of floating-point numbers At the top of a program (or the beginning of it) You should list all your import statements Then usually create your variables (don’t scatter throughout your code Hardware: ○ The tangible, physical, parts or peripherals of a computer that run things and obtains input and provides output ○ Examples: Keyboard, screen, storage, processors, microphones, USB interfaces, speakers, printers, etc. High-Level Languages: ○ Languages invented in the 1960’s and 1970’s to support programming using formulas or algorithms ○ More abstract and related to human language than machine or assembly ○ Some of the earlier languages were FORTRAN (Formula Translator) or ALGOL (Algorithmic Language) Identifier (or Name): ○ The title given to something ○ Cannot be used at for any other thing in the program (see identity) ○ In Python: This can include letters, underscores, and digits (0-9), not symbols or spaces This must start with a letter or underscore (try to avoid double underscores) Names are case sensitive Identity: ○ The unique numeric identifier given to each object (like 1, 500, or 45382) ○ Like a SSN or student ID, only one object at any time may have a particular identifier ○ Usually refers to the memory address where the object is stored ○ The built-in function id() can give the value of an object's identity ○ See id() in python pedia Immutable: ○ Means the value’s type cannot be changed ○ Integers and strings are immutable ○ Checking if it can be changed is mutability ○ Think immortal (cannot die) Increment: ○ Incremental Development: A good practice Writing, compiling, and testing a small amount of code, then repeating the process with a small amount more (an increment), etc. You should “save as” and update the file name every couple sections (iteration) ○ Incrementing: Increasing by a set amount over and over again Opposite is decrementing Example with picking up nickels each being worth 5 cents wallet = 0 nickel_value = 2 wallet = wallet + nickel_value Shortcut: wallet += nickel_value (also for *=) Indentation: ○ See whitespace Input: ○ The information that a user gives to a program (usually after having been asked a question); info that a program receives, usually to do something with it ○ Examples: Touchscreen Typing on a keyboard Files I create ○ A program receives (gets) data from a file, keyboard, touchscreen, network, etc. (we then will usually process that data and you should use a print statement to output it) Index: ○ A character or element’s position in a container (like an address) ○ Starts with 0 (left to right) ○ CANNOT be a float (no such thing has half a human, or half an address) ○ Example: ○ To see what value is held at a specific index position, use the variable name[#] ○ A negative index is the character building from the last right character of the string, instead of first left ○ In the alphabet, -1 would be Z, and -3 would be X ○ See zyDE 3.1.2 for an example Instruction: ○ A list of calculations for processors to execute ○ Operate on data, which is stored in memory locations as 0’s and 1’s Integer: ○ A data type that allows a number ○ This number CANNOT have decimals ○ This cannot be written with a comma (1234567 not 1,234,567) ○ In general, integers should be used to represent quantities that are counted, such as numbers of cars, students, cities, hours, and minutes ○ See int() in python pedia Integrated Circuit (IC): ○ Transistors integrated into a single chip ○ Following Moore’s Law, there are now several billion transistors containing multiple processors in an IC (each called a core) Integrated Development Environment (IDE): ○ A software that programmers use to build and run code ○ It knows how to interpret code as more than just text Interpreter: ○ Executes a script ○ Slower because it requires multiple interpreter instructions to execute one script instruction ○ BUT it avoids the compilation step during programming and running the same script on different processors as long as each processor has an interpreter installed ○ Interactive Interpreter: A program that allows the user to execute one line of code at a time (the Shell) ○ Python Interpreter: A computer program that executes code written in Python ○ Executes in order: the first line of code at the top all the way to the end (bottom) Irrational Numbers: ○ Numbers that can’t be written as a ratio (simple fraction), and would therefore have infinite numbers after the decimal ○ Click for an explanation ○ Example: 3.1415… Iteration: ○ Saving AS periodically BEFORE you make changes (like every 5 minutes or 5 lines of code) ○ So you can go back to the better soup before you accidentally added ½ cup of garlic like Miss Haan ○ A NAMED version of something ○ Think Iron Man’s versions of his suits: Mark I, Mark II, etc. ○ A good practice Keyboard: ○ Hardware that allows users to provide input to a computer Keywords (or Reserved Words): ○ Certain words that the Python language already has a meaning for and therefore cannot be used as programmer-defined names ○ Link to list ○ Leading Zeros: ○ Zeros before a number, like 007 instead of 7 Line: ○ A row of code List: ○ A container made by surrounding a list of variables or literals (can be mixed data types) with square brackets ○ See visual aid chart ○ Each item in a list is called an element, and like a string, each element has an individual address, known as an index ○ A sequence type where the list name and every element is its own object ○ Useful for reducing the number of variables needed in a program ○ You can change, append, and remove ○ To see some functions and methods that are useful with lists, click to see a chart (linked in sequence type) ○ Example (see how to make in python pedia): my_list = [10, 'abc'] print(my_list) [10, 'abc'] Literal: ○ A specific value in code, like 2 ○ Entered directly into the code as is, instead of 1 + 1 Logic Error: ○ See bug Machine Instructions: ○ Computer instructions that are represented as 0s & 1s Megabyte: ○ A million bytes Memory: ○ A circuit that can store 0’s and 1’s in each of thousands of addressed locations ○ Like a series of mailboxes with address that can each store an envelope (the 0’s and 1’s) ○ The arrangement is similar to a chef (processor) executing the instructions of a recipe (program), where each instruction changes ingredients (data), with the recipe and ingredients kept on a nearby counter (memory). Method: ○ Instructs (tells) an object to perform some kind of action ○ Like a function, but associated with an object (a function is not) ○ Used to make general things (classes) do more specific or different things ○ Called using a dot notation ○ See how to execute a method here in python pedia ○ Call a method using dot notation by writing the method’s name, dot, followed by the object ○ Larger idea (or program name), then period, then the smaller idea (or specific object) name ○ See how to execute a method here in python pedia Microprocessor: ○ A term used when processors started to fit on a single chip ○ Continue to get smaller and more capable, following Moore’s Law Module: ○ A file containing Python code that can be used by other modules or scripts ○ Can be made available for use by using the import statement (see python pedia) ○ Import statement should be at the top of the file ○ Use an object (like a variable or function) within the module after import using the dot notation (see python pedia) ○ Splitting code into separate modules makes managing larger programs simpler ○ There are pre-installed useful modules available in the Python Standard Library ○ When it is imported, all code in the module is immediately executed ○ Math Module: A standard module that comes with Python to support more advanced math Includes theoretic, trigonometric, and logarithmic operations Click for list of functions from math module Access by: import math Examples: square root ○ Random Module: Provides methods that return random values Numbers generated are pseudo-random See random() in python pedia See randrange() in python pedia See randint() in python pedia Moore’s Law: ○ The principle that the speed and capability of an IC can be expected to double every 2 years (now 18 months) ○ Came as a result of more and more transistors being able to be contained by a microchip Mouse: ○ Hardware that allows a user to provide input to the computer using graphical displays Mutable: ○ Means a value’s type or contents can be changed ○ Opposite of immutable Mutability: ○ Refers to whether the object's value is allowed to be changed or is immutable ○ Modifying the values with assignment statements results in new objects being created and the names bound to the new object ○ Think TMNT Name (or Identifier): ○ See identifier Name Binding: ○ The process of associating names with interpreter objects ○ An object can have more than one name bound to it (many people can be 14 years old) ○ Every name is bound to exactly ONE object (but Haan can only be 14, not 14 and 19) ○ Occurs whenever an assignment statement is executed ○ Examples linked in zyBooks 2.3.2 Naming Conventions: ○ Following a system for giving names ○ Give names that make sense, are useful, and cannot easily be confused ○ You should be able to tell what a function/variable is about by its name ○ Good practice ○ Avoid: Also check identifiers and keywords Double underscore before names I i, L l, 1 O o, 0 x Nesting: ○ Placing commands within one another, usually with parenthesis ○ Should not be separate or cross one another (connect into a circle) ○ Think of Russian nesting dolls ○ Correct example: int(input()) ○ Incorrect example: int()input() Non-Volatile: ○ Means the item maintains its contents, even when powered off; opposite of volatile Numeric Type: ○ A data type that supports normal mathematical operations (+,-,*,/, etc.) ○ Includes: Integer Floating-Point Object: ○ A thing that represents a value and is automatically created by the interpreter when executing a line of code (including integers, strings, functions, lists, etc.) ○ Not explicitly made by the programmer, but rather created and manipulated as needed by the interpreter ○ Interpreter automatically assigns each new object a location somewhere in memory, and when it is no longer needed, it is automatically deleted from memory and thrown away (aka garbage collection) ○ Example: Executing yrs_of_high_school = 4 Creates a new object to represent the value 4 Check 2.3.1 for more examples ○ Properties (every Python object has all 3) Value: The data associated with the object, such as the 4 above, efadfg, or mom Type (or Data Type): The supported behavior of the object, like float or string Object type NEVER changes once created Identity (or Identifier): A unique name that describes the object Open-Source: ○ Means that the community of users participate in creating and defining something Operand: ○ The numbers/variables/values used in an equation ○ Example 5 * 7 The 5 and 7 are operands Operating System (OS): ○ A program that allows a user to run other programs and interfaces (interacts) with many other peripherals Operator: ○ A symbol that performs a built-in calculation (like + does addition) ○ The types of the values being compared determines the meaning of a comparison If both values are numbers, then the numbers are compared arithmetically (5 < 2 is False) Comparisons that make no sense, such as 1 < 'abc', result in a TypeError Comparison of values with the same type, such as 5 < 2, or 'abc' >= 'ABCDEF', depends on the types being compared ○ Specific to types: Numbers are arithmetically compared Strings are compared by converting each character to a number value (ASCII or Unicode), and then comparing each character in order (Most string comparisons use equality operators "==" or "!=", as in today == 'Friday') Lists and tuples are compared via an ordered comparison of every element in the sequence. Every element between the sequences must compare as equal for an equality operator to evaluate to True. Relational operators like < or > can also be used: The result is determined by the first mismatching elements in the sequences. For example, if x = [1, 5, 2] and y = [1, 4, 3], then evaluating x < y first evaluates that 1 and 1 match. Since the first list elements match, neither list can be considered to be less than the other, nor can the lists be declared equal without comparing more elements. So the next elements must be compared. The next elements do not match, so 5 < 4 is evaluated, which produces a value of False. ○ Arithmetic Operators: ○ Compound Operators: Shorthand (or shorter/shortcut) ways to update variables Output: ○ Information that a program gives (its response); info received from the program - usually for a user to see ○ Examples: Your screen A pop-up The letter that shows up when you type on the keyboard ○ If the directions say output, it probably means use the print command (which creates output) ○ Usually after receiving input, you’d like to process and then output it to see what they said and do something with it OverflowError: ○ Overflow occurs when a value is too large to be stored in the memory allocated by the interpreter ○ A standard 32-bit installation of Python… Maximum floating-point value is approximately 1.8x10308 Minimum floating-point value is 2.3x10-308 ○ Error is created when you assign a floating-point value outside of the allowed range Peripherals: ○ The hardware used to receive input or display output ○ The input/output (I/O) devices Precedence Rules: ○ The order in which an expression is evaluated ○ Good practice: Always use parentheses to make order of evaluation explicit ○ In math, order of operations ○ ○ Presentation Type: ○ The “how” (right side of the colon in a format specifier) that determines how to represent a value in text form ○ How you want the stuff in the replacement field to be “presented” in the output ○ See examples and how-to here in python pedia Process: ○ A program performs computations on input, like x + y Processor (or CPU or Microprocessor): ○ Runs the computer’s programs, reading and executing instructions from memory, performing operations, and reading and writing data to and from memory ○ Computes data, while memory stores data and instructions ○ Because speed (which is maintained by a clock) is important, it may contain a cache ○ How it works: Circuits made to process (or execute) a desired list of calculations When powered on, the processor starts executing the (BIOS) Then it executes the OS program ○ The arrangement is similar to a chef (processor) executing the instructions of a recipe (program), where each instruction changes ingredients (data), with the recipe and ingredients kept on a nearby counter (memory). Program: ○ A programmer-created sequence (goes one at a time, in order) of instructions Programming Language: ○ A language can be scripting and programming ○ Used for larger and more complex software than scripting languages, like an OS ○ The TIOBE Index for most popular programming languages Pseudo…: ○ A prefix that means not actually, but looks like ○ Pseudocode: A detailed (but readable) description of what a computer program should do (that’s easier for humans to understand) ○ Pseudo-Random: The random module has an equation to calculate the next “random” number from the previous one while it invisibly keeps track of the previous one The first time you call any random method, there is no previous random number, so the method uses a seed to help generate the number Despite the appearance of randomness, reproducibility is important for testing Python: ○ A scripting language released in 1994 with the goals of simplicity and readability while maintaining other language’s power and flexibility ○ Facts: Excels at providing powerful programming paradigms such as object-oriented programming and dynamic typing Incurs additional overhead costs because the language is interpreted, and creates slower-executing programs Came from an existing language called ABC Named off of Monty Python’s Flying Circus Python 2.7 is not backwards compatible (see article) Is open-source Python Enhancement Proposal 8 (Pep 8): ○ The Python style guide, very useful for good practices ○ Linked here ○ “Code is read more often than written, so having a consistent variable naming scheme helps to ensure that programmers can understand each other's code” Random-Access Memory (RAM): ○ A computer component that temporarily holds data read from storage (disk or flash) ○ Usually located off the processor chip ○ Designed so any address can be accessed much faster than from a disk ○ “Random access" comes from accessing any memory location quickly and in random order, without spinning a disk to get a proper location under a head ○ More costly per bit than disk because of its higher speed ○ Memory size is typically listed in bits or bytes (megabytes, gigabytes, or terabytes) Reciprocal: ○ In math, it’s the inverse (opposite) negative or opposite ○ Divide it by 1 Refactoring: ○ Using the simplest or most efficient code; simplifying ○ Example pocket_of_coins = pocket_of_coins + 1 pocket_of_coins += 1 Repeating Decimal: ○ Numbers where the “last number” after the decimal would repeat infinitely ○ Example: 4.333333333… Replacement Field: ○ A placeholder expression ○ Its value replaces the expression in the final output, like in an f-string ○ Specify the formatting with a format specification ○ In an f-string, it’s whatever is in { } ○ A placeholder expression that is identified with {} in an f-string ○ If a variable is in the {}, it will be replaced with the variable’s value when printed; whatever value replaces the expression in the final output in an f-string ○ You can put any data type in the {}, but after printing it will all be a string ○ Change how the data looks when it’s printed with a format specification ○ See examples and how-to here in python pedia Respectively: ○ In the order they’re mentioned, separately or individually ○ More specifically in math, if 2 lists are listed, they should be matched up in the same order Runtime Error: ○ An error where the syntax is correct, but the program attempts an impossible operation ○ It may also be given something “unexpected” ○ Can be ValueError, NameError, etc. ○ Example: 0/0 print(‘Hello’ * ‘ABC’) Screen (or Monitor): ○ Hardware used to display items to a user Scientific Notation: ○ A way of writing very large or very small numbers so it can more conveniently and shortly written in a decimal form ○ Uses an "e" preceding the power-of-10 exponent (see python pedia) ○ Examples: 6.02*1023 is 6.02e23 0.001 is 1*10-3, so written as 1.0e-3 ○ For review, go to 2.4.1 PA Script: ○ A program whose instructions are executed by an interpreter ○ It is a saveable file, not like the Shell Scripting Language: ○ A language created in the 1960’s and 1970’s to execute programs without a need for compilation ○ Used for smaller tasks than programming languages Seed: ○ A built-in integer based on the current time ○ Used in the random module to generate a pseudo-random number ○ Useful because the program will be run at different times each time, so each program will get a unique sequence ○ To reproduce a test run without different integers, see seed() in python pedia Sequence Type: ○ A data type that is a kind of container that can hold a bunch of things in a specific order (left to right) and can be accessed using an index (address) ○ There are several kinds of “containers”, some that allow you to change what’s inside, and some that stay the same once you put things in ○ It’s important to pick the right one for your program goals ○ To find the length of any, see len() in python pedia ○ Some types of “containers” include: ○ Strings (like a string of beads, you can't change the color of one, it stays as is) ○ Lists (like a backpack, you can put different things in there, change what’s in side, add more, or take things out) ○ Tuples (like a locked buried treasure, it can have a variety of things inside, but you can’t add or take away, so it stays the same) ○ Sequence-Type Functions: ○ Built-in functions that work on sequence types (like lists and strings) ○ See below chart for ones that are useful for lists ○ Set (or Set Type): ○ A mutable unordered collection of unique elements (doesn’t allow duplicate values) ○ Set properties: Elements are… Unordered: Elements in the set do not have a position or index Unique: No elements in the set share the same value ○ Holds the elements of an iterable object sequence type (like a list, string, etc.) ○ Often used to reduce a list of items (that may contain duplicates) into a collection of unique values ○ Simply passing a list into set() will cause any duplicates to be omitted in the created set ○ See set() in python pedia Software: ○ The intangible parts of a computer, the programs Statement: ○ A program instruction, usually just on one line ○ A program is usually a series of statements String / String Literal: ○ Empty String: A sequence type with 0 elements (nothing between “”) ○ Generally, a data type (more specifically, a sequence type) that includes anything enclosed in quotation marks (letters, numbers, spaces, and symbols) ○ Numbers will NOT be read as numbers - they have NO mathematical value ○ Examples: The string 'Hello' consists of the characters 'H', 'e', 'l', 'l', and 'o'. The string '123' consists of the characters '1', '2', and '3'. ○ Can use single, double, or triple quotes but… using single quotes for shorter strings and double quotes for longer or more complicated text that contains quotes is a good practice Examples print(‘Hello world!’) print(“I cannot say ‘hello world’ again!”) ○ String: Basically the variable name that is holding the string literal (sometimes used interchangeably as the variable itself or data type) ○ String Concatenation: Adding more characters onto an original string using a + Strings are immutable (you cannot change individual characters in a string) To make changes to what exist in that space, you must make an assignment statement to update an entire string variable You may add to the end of string by using concatenation, which doesn’t contradict the immutability because the result is a new string, leaving the old unchanged ○ String Literal: The part inside the quotation marks (refers to the “” content a variable holds) LITERALLY the string ○ The characters inside are ordered left to right, and each one’s position is its index ○ To check the length (how many characters) are in a string, see len() python pedia ○ See escape sequence for ignoring a quotation mark in a sentence ○ See f-strings Storage: ○ Keeps/stores files and other data (like programs, songs, movies, documents, etc.) ○ May be volatile or non-volatile ○ Usually a disk or flash Sunset: ○ To plan to remove or discontinue something in IT; end-of-life Switch: ○ Switches control whether or not electricity flows through a wire (on and off) ○ Switches can be controlled electronically ○ In an electronically controlled switch, a positive voltage at the control input allows electricity to flow, while a zero voltage prevents the flow ○ A positive voltage is seen as a "1" and a zero voltage as a "0" Syntax: ○ The programming language’s rules on how symbols can be combined to make a program Syntax Error: ○ A syntax error means that it violated syntax rules ○ A common error is to use = rather than == in an if-else expression, as in: if numDogs = 9:. In such cases, the interpreter should generate a syntax error Terabyte: ○ A trillion bytes Transistor: ○ Smaller switches created when computers were as large as rooms Type: ○ See Data Type Unary: ○ A unary minus sign is used to make a number negative ○ Part of the precedence rules ○ “You-nair-ee” (video) Unicode (or The Unicode Standard): ○ A system for text encoding that represents every possible character with unique numbers (over 1 million) that are known as code points ○ Designed to support the use of text written in all of the world's major writing systems (version of letters) ○ They exist for visible characters and special characters (example, the newline character, which is two items, but not read as such) ○ Python’s official how-to with Unicode ○ Click for all charts ○ Click to check Unicode text values in zyBooks (2.11.3) Value: ○ Object: The data associated with the object, such as the number 4, ‘efadfg’, or mom ○ Dictionary: Describes some data (any data type) associated with a key (like the definition) Variable: ○ A label for data (like a box when you’re moving ACTUALLY NOT, READ THIS) ○ A named reference ○ Uses an equal sign to assign the label ○ Example: name = miss_haan Volatile: ○ Loses its contents when powered off; opposite of non-volatile Whitespace: ○ Indentations (usually tab or 4 spaces), a new line, or a space ○ Can be required or optional ○ Often used to show the boundaries areas of code, or to show the relationship from one line to the other (like parent/child) ○ Don't let 1 line of code go past 80-120 characters/spaces (aka columns) - but 80 is the more widely accepted standard. If it must wrap to the next line, it should start and end in parentheses, and each line should start at the same “level” (number of spaces) as the beginning of the extending line (it is not considered a block, so do not have to be at intervals of 4)