1D04 Final Summary.pdf

7 Pages

Engineering (General)
Course Code
Spencer Smith

This preview shows pages 1 and half of page 2. Sign up to view the full 7 pages of the document.
TOPICS 1. Computing. • What computing is. ◦ Computing is the development and use of the computer hardware and software to: ▪ Solve problems. Create smart products. Explore our world. Connect people. ◦ Computing is a mixture of: ▪ Science, Engineering, Mathematics, and Design. • Main branches of computing. ◦ Computer Science. Software Engineering. Information Technology. • Why engineers need to study computing. ◦ Computing is used everywhere in today's world. ◦ Software-based tools can enhance the capabilities of engineers. ◦ Software can increase the effectiveness of the products engineers design. ◦ Solid understanding of computing is a crucial component of being a competent and ethical engineer. ◦ Computing contains lots of engineering ideas. 2. Mathematical Concepts. • Number systems. • Sequences (finite and infinite). • Σ and Π notation. • Functions. • Boolean operators and truth tables. 3. Programming Languages. • Values and types. ◦ Values are the data stored and manipulated by the computer programs. ◦ Types is a syntactic entity that denotes a collection of values of similar form. • Expressions. ◦ Asyntactic entity that denotes a value. ◦ Avalue will always be a result of an expression. • Variables and constants. ◦ Variables: ▪ The exact definition of a variable varies across disciplines and contexts. ▪ In Python, a variable is a name bound to a value. ◦ Constants: ▪ Python built-in constants includes True and False. ▪ Convention dictate user-defined constant to be written in all capitals. ▪ Python allows changing of constant without restrictions. • Statements. ◦ Is a syntactic entity that states something to be done. ◦ Statement DOES something (like assigning a value to a variable). • Representation of number systems. ◦ Review on how to convert to base 10 decimals. ◦ Review on how to convert base 10 decimals to another base. • Characters and strings. ◦ Characters: ▪ In computing, character represent graphemes (the unit of a writing system). ▪ ASCII: • Based on English alphabets. Contains 128 characters represented by character of 7 or 8 bits. ▪ Unicode: • Represent the graphemes of world major writing system. • Characters represented by 8, 16, 32 bits. ◦ Strings: ▪ Is a finite sequence of characters. • Function definition and application. ◦ Functions are subprogram that: ▪ Are defined and applied by the developer. ▪ Reduce code duplication. ▪ Improve software quality (maintainability, understandability, reusability). ◦ Evaluation steps for a function: ▪ Calling program is suspended. ▪ Values of formal parameter are bound to the values of actual parameter. ▪ Body of the function is executed. ▪ Output value of the function is returned to the calling program. ▪ Calling program execution is resumed just after the function was called. ◦ Side-effect ▪ Python passes parameter by value. If the value being passed is a mutable object, then changes made to the object may be visible to the caller. ▪ Aliasing problem in a object is an example of side-effect. ▪ Basically, any changes made by the function NOT through the return method is a side-effect. ▪ Note that changes includes modifying the display. Like printing a data using print x instead of using return x. ▪ Aproper function makes no changes in the environment. It receives arguments, computes a value, and returns it. Anything else is a side effect. • Name spaces and scope. ◦ Namespace ▪ is a space that holds a bunch of names ▪ each namespace is isolated (per module, function, etc) ◦ Scope ▪ is a region of program where a namespace is accessible ▪ the scope in which a name is declared determines what namespace the name is in ▪ scope are nested ▪ normally a variable created outside of the innermost scope is read-only within the innermost scope • Modes of execution. Python supports all three of these modes. ◦ Interpreted: ▪ Running the code line by line. ▪ Supports interactive development and debugging of code. ▪ Slower than executing compiled code. ◦ Compiled into byte code: ▪ Programs are more portable. ▪ Byte code is slower than native code. ▪ Python's byte code end with *.pyc. ◦ Compiled into native machine code: ▪ The machine code is optimized to run fast. ▪ Code development is more difficult. • Programming paradigms. ◦ Programming paradigms is a well-developed style of programming. ◦ Chief programming paradigms: ▪ Imperative – Program statements modify a program's state. ▪ Object-oriented – Data and operations are organized into units called objects. ▪ Functional – Functions are first-class values and function applications are side-effect free. ▪ Logical –Answers to questions are deduced from logical statements. ◦ Python supports all these paradigms except logical. 4. Values, Types,And Expressions In Python. • Numeric types. ◦ Int: ▪ 32-bit machine integers. +ve or -ve whole numbers. ▪ Integer divisions is a pitfall to watch out for. ◦ Long: ▪ Used to store integer of arbitrary size. ◦ Float: ▪ 64-bit floating point fractional numbers. ▪ Can be shown in scientific notation. ▪ Floats can only stored approximations to real numbers. • Thus avoid testing x == y or x != y when x and y are floats. ▪ Floats are fixed digits that has no relation to memory. • Sequence types. ◦ String is immutable finite sequence of characters. ◦ List is mutable finite sequence of values (the values can have different types). • Objects. ◦ Data ▪ Field – define the object's state, which is the set of information that is stored in the object. ◦ Operations ▪ Methods – define the object's behaviour. • Accestor (aka selector or getter) – is a method that retrieves information about the state of an object. • Mutator (aka setter) – is a method that modifies the state of an object. ◦ Aliasing Problem ▪ In Python, aliasing consist of the same jar model.As in, the same data can be called and changed by different variables. ▪ This is only a problem with mutable object (which string is not). • Booleans and boolean operators. ◦ Logical Operator ▪ NOT > AND > OR ◦ Boolean Properties ▪ Anything ORED with True is just True. • a or true == true ▪ Both AND and OR distribute over each other. • a or (b and c) == (a or b) and (a or c) • a and (b or c) == (a and b) or (a and c) ▪ Double negative cancels out. • not(not a) == a ▪ De Morgan's Laws: • not(a or b) == (not a) and (not b) • not(a and b) == (not a) or (not b) ◦ Implicit Type Conversion ▪ Values of built-in non boolean types are implicitly converted to boolean values when they are used as booleans. ▪ Empty values equals False. ◦ Short-Circuit ▪ Used forAND and OR. ▪ Is an evaluation process that returns an answer as soon as the result is known without evaluating all of its sub-expressions. • “cat” and “dog” gives “dog” since “cat” returns True • “cat” or “dog” gives “cat” since “cat” returns True • if x = 3 then x == x and x + 4 gives 7 when evaluated • Exceptions. ◦ Raise statement ◦ Try-except statement ▪ Try-except is capable of catching multiple type of errors but not all at once. • Type conversion. ◦ Type error ▪ Occurs when one type is used where another type is expected. ▪ Types are used to catch type errors at run-time. ◦ Python will automatically converts values in mixed type numeric expressions to resolve type conflicts. The value of the “narrower” type will be converted to the “wider” type. ▪ Eg: 2/3.4 is converted to 2.0/3.4. 5. Statements In Python. • Assignment statements. ◦ Used to assigned a identifiers to a value. ◦ Identifiers begin with underscore or letter. Followed by a combo of: letter, digit, underscore. Identifiers are case sensitive. • Conditional statements. ◦ Selects a statement for execution on the basis of whether a condition represented as a Boolean expression evaluates to True or False. ◦ Different kind of conditional statements includes: if, if-else, if-elif-else, try-except, and while statements. • Definite loops. For loop. ◦ Can be made into indefinite loop under certain events. • Indefinite loops. While loop. Can be broken using break. ◦ Interactive loops. ◦ Sentinel loop (until a sentinel value is met). ◦ File reading loop (until end of file). ◦ Repeat-until loop (until a condition is met). ◦ Infinite loop. • Function definitions. ◦ >>> def function_name(formal_parameter): ◦ >>> return value ▪ Used to obtain a result of the function. ▪ Function will always return a value even if return is not used. When return is not used, function will return a special object NONE. ▪ If multiple values are return, then a special type tuple is returned. • Tuple: ◦ Has round brackets. ◦ Are immutable. ◦ Can be accessed using index notation. • Exception handling. ◦ >>> try: ◦ >>> statements ◦ >>> except Exception1: ◦ >>> exception_handler1 • Class definitions. ◦ >>> class class_name: ◦ >>> def __init__(self, formal_parameter): ▪ Is a special constructor for class. Its job is to create the class as a object. • Method definitions. ◦ Is a definition of a function within a class. Used the same syntax and involves the same properties of a regular functions. ◦ The only different is to access a method function within a class, one would need to use a do
More Less
Unlock Document

Only pages 1 and half of page 2 are available for preview. Some parts have been intentionally blurred.

Unlock Document
You're Reading a Preview

Unlock to view full version

Unlock Document

Log In


Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.