Unit 2 "Writing and Testing Code", Unit 3 too

¡Supera tus tareas y exámenes ahora con Quizwiz!

Python's Data Structures

"...In Python, however, lists and arrays have distinct qualities and must be handled differently." - lists are a mutable data type, which means that they can be changed after they are created. They can be made up of combinations of different object types, such as ints and strings. - arrays are an immutable data type, which means they cannot be changed once they are defined. In Python, all of the elements in an array must be of the same object type.

Two types of variables

- Local variable: a value that can be used only from the block of code where it is declared, therefore it cannot be changed. (in Python, local variables are any variables that are created or changed within a function.) - Global variable: a value that can be called and used anywhere in the entire coding project; any part of the program can access and change it. (In the Python programming language, a global variable is declared with the keyword global.)

Data Types in Python

- Numbers: numeric values; there are four types; int, long, float, & complex. - Strings: are connected sets of characters between two quotation marks "/', uses + & * to connect and repeat, respectively. -Lists: which are sets of data separated by a comma between two brackets [ ]. Items in a list can be of different data types. - Tuples: which are sets of data separated by a comma between two parentheses ( ). Unlike lists, these cannot be changed, only read. - Dictionary: is a container. A large and changeable list that can contain any number of Python objects, enclosed by { } and separated by commas. The Python dictionary has unique keys, which cannot be changed, and are separated from their values by colons ; .

Required and Keyword Arguments

- With a required argument, the number of arguments in the function call should match exactly with the function's definition. - Keyword arguments don't need to be listed in a specific order, and can be left out of a function call. The caller identifies the arguments by parameter name. ???????

(python's 4 numeric data types )

- int: integer. - long: large number. - float: floating-point number. - complex: mixture of numbers and characters. (most commonly used numeric types are int and float.)

Properties of a Variable

- name - extent (in time) - scope (in space, either global or local)

Common Data Types

-Alphanumeric strings: are mixed sequences of letters and numbers - Boolean operators: variables that can hold one of two variables: t or f. - Characters: individual letters, numbers, or symbols. - Floating point numbers: moveable decimal points in a number, rather than fixed. - Integers: numeric whole-number values, either pos. or neg.

Definitions of Variables

-Scalar: a single number or value that may include an integer, a floating-point decimal, or a string of characters. -Array: a group of related scalar or individual values assembled into one new entity, such as a sequence of numbers or letters. -UDTs: user-defined type is a data type in which programmers assign their own true or false values to the data type. - ADTs: abstract data type is a data type in which multiple values are assigned to a single data type.

Components of IDEs that translate the high-level language into machine language for the computer are called:

-compilers. -interpreters. (some IDEs include just a compiler or an interpreter, while others contain both)

developer forums, blog

-dev forum... virtual meeting place, searchable, usually hosted by software compnies, some require registration -blog... online post made by individual, often with reference links

online helps sites, forums, user manuals, & tutorials

-online help.... websites usually hosted by the software company that developed the software language that contain FAQs and reports. -forums... virtual meeting places that allow users to post questions that will be answered by other users. -user manual... combine text & image, explain features of program, include chapter on how to solve common issues, contain syntax. -tutorial... step-by-step, might new feature, specific task.

single/cross platform IDEs

>Cross-platform IDEs - designed to be used on multiple operating systems (such as Microsoft Windows® and Mac OS X®), some can be used with any system that has a web browser. >Single-Platform IDEs - only support a single operating system.

sequence index

A Python loop statement that uses a built-in function called length, or len(). Provides the total number of elements in the ordered list of elements, as well as the range (used as an alternative to iterating through each item). "An alternative way of iterating through each item using its index in the sequence." (?)

A subroutine

A block of code given a unique identifiable name within a program. Supports code reuse and good programming technique. May be used to refer to a procedure, function, routine, method, or subprogram. They can contribute to excessive use of a computer's resources.

Writing a Custom Function

A custom function is one that a programmer creates for a specific task in the program; unlike a built-in function, it must be defined before it can be called. When programmers define a function, they write a function and add it to a program's library. A function definition refers to code that declares the name of the function and the action or actions that it performs. Defining a function is not the same as calling a function. A function can be defined, and then never called, but a function cannot be called if it has not been defined first.

A value

A definite object. **represents content in a computer program that is returned by a function; it is the result of a function.

For Loops

A for loop is a control flow statement that iterates through a block of code. The loop can be written to perform a certain number of iterations or to iterate until a specific result is achieved.

Arguments and Return Values

A function sometimes requires data, such as an int or string, to execute its task. For example, the print() function takes a string such as "Hello, world!" and then prints it. The input data of a function is called an argument, and a function may take one or several arguments. Some functions produce a return value, which is the output data of a function. You can think of the role of a function as being similar to a math problem. For example: a * b = c "multiply" is the function a and b are the arguments c is the return value A function's return value depends on the values of its arguments, but the action the function executes is always the same.

Built-In Functions

A function's commands are stored in either the program itself or the development environment. When you call a function, you tell the program to run the stored code for the function. A built-in function is a function that comes with a programming language's development environment; it does not have to be defined in the program. The Python development environment comes with many built-in functions, such as print(). When you write a program in Python, you can call any of the built-in functions in the standard library.

While Loops

A while loop is a control flow statement that iterates some code as long as its stated condition is in effect. The condition is usually a Boolean expression that returns a value of True or False. You can think of a while loop as a repeating if-then statement. Using the earlier dishwashing example, the logic in a while loop would look like this: When no more dirty dishes exist, the loop ends.

Variable Input in Conditional Statements

An If statement needs a value to evaluate against its condition, but sometimes that value must come from the person using the program. To write this type of If statement, programmers must declare a variable with a value that is determined by user input. Here's an example: When the above code is run, the prompt will ask the user to "Type an integer" and then assign that value to the variable "integer_input." For this lesson, you will write an If statement that prints a string (or not) based on the value of an integer variable that will be determined by user input. Next, you'll start a project file to practice writing conditional statements in Python.

The Use of Print(i) in Loops

As your project demonstrates, the print(i) function prints the value of the i variable during each cycle of the loop. When looping through the colors list, the variable i takes the index of each list element in succession as its value. In the loop with the range() function, the i variable takes as its value the new number generated by range() with each iteration. Using the print() function for each cycle of a loop is one way to make sure that the loop is working correctly, especially for more complicated loops.

George Boole (1815-1864)

Boolean data type, self-taught English mathematician, logician & philosopher.

A constant (vs. a variable)

Both constants and variables are variations of data types. A variable and its value can be changed by the program as it runs. A variable is essentially a storage space for a value. A constant has a fixed value that cannot be changed by the program as it runs. It replaces the value by defining it. A constant can be local or global.

Bugs

Bugs are any errors in a computer program. Bugs fall into three categories: Syntax errors, where the programming language usage rules were not followed Semantic errors, where the programmer misunderstood something in the programming language Logic errors, where a mathematical calculation in the program code was incorrect

Elif Statement Syntax

Conditional statements with multiple conditions follow this pattern: If a condition is True, then do something. Or else, if the first condition is False, then check if a second condition is True. If it is, then do something different. Or else, if both conditions are False, then do a third thing. Take a look at the syntax for constructing If and Elif statements, as shown at right.

about: Interpreters , in depth

Coputer app, tanslates & excecures each instruction or line of code from hi-lev-lang to binary. so it takes longer than computer, & also possible to change the source code program while the program is running.

Debugging code

Debugging a software is an iterative, or repetitive, process, meaning the steps may need to be taken repeatedly. Debugging can occur throughout the testing and fixing process Many integrated development environments (IDEs) include debugging software that allow a programmer to investigate the source of an error by: stepping through the program line by line. establishing breakpoints, which means to run the code from one selected point to another, and to manage the testing of the program in segments. watching where the data is stored in program memory to ensure that the correct values are being calculated or captured.

Ways to Use Iteration to Step through a Data Structure

Elements can be added and removed from a data structure in specific ways: Stack: "last in, first out." New elements are added at the end of a sequence, and the element at the end is the first to be removed. Queue: "first in, first out." New elements are added at the end of a sequence, and the element at the beginning of the sequence is the first to be removed. Deque: double-ended queue, pronounced "deck." Elements in a sequence can be removed and added at either end of the structure.

"weakly typed" & variables and data types

If a programming language is weakly typed, the data type does not have to be stated before the variable can be used. The data type will be determined automatically when a value is given to the variable. In this type of language, the data type (e.g., an integer) does not have to be specified before the value is declared. Example; Python.

Python Array Module

In Python, lists and arrays are treated somewhat differently than in other programming languages. What Python calls a list would be called an array elsewhere, but a true Python array operates under special rules. In Python, arrays are usually reserved for numerical operations, such as sorting numbers from lowest to highest. In addition to the list methods, arrays can make use of a class of methods defined in the Python array module

Handling Remaining Possible Conditions (Else statement), (Else statement syntax)

In Python, programmers use the Else statement to run some code when all the conditions in the preceding If and Elif statements evaluate as False. -Else statements do not use conditions. They are written at the end of a series of conditional statements, after the If and any Elif statements. For example, in the code at right, Python will print "Hello" if the value of first_variable is greater than 6. If the value of first_variable is not greater than 6, Python will print "World".

If Statement Syntax in Python

In Python, the first line of an If statement has three parts: the word "if" the condition, which must be a boolean expression a colon ( : ) Below the first line comes the block. This is the series of commands that Python will run when the conditional statement is True. The block can be one line long or multiple lines. Python uses indentation to show where the block starts and stops, so you must put an equal number of spaces in front of each line of the block. In the Python programming language, the recommended amount to indent is four spaces. Because the default indent in the Python IDLE text editor is set to four spaces, you can use the Tab key to indent lines of code the right amount in the IDLE.

Escape Characters

In Python, the programmer must specify the object type of the elements to be stored in the array. A type code is a single character that defines whether the objects stored in an array are signed or unsigned integers, floats, or characters. For example, 'I' is the type code representing an array of unsigned integers, like this: array('I', [1, 2, 3])

a function is

In computer programming, a function is a block of code that performs a specific task. Programmers can reuse a function to execute the same task in different parts of a program. Functions are useful for grouping actions logically so the program completes tasks in an order that produces a correct result. They can be combined to complete more complicated tasks. Because a function describes what it does in its first line, using functions makes reading code easier. For example, print() is a basic Python function that can print a string or the value of a variable on the screen.

A variable

Is a storage location for a value, and a component or symbol in a computer program. Variables store values or sets of values. They can: - store temporary data. - store values of different data types; they are flexible. *Code with variables is easier to reuse and reduces the amount of coding required.

conversions between numbers systems can be...

Made with one of the widely available online converters or translators, or, they can also be made manually by looking up the values in conversion tables.

List Methods

Methods are functions that are associated with a class of data types. List and array data types are classes that have methods associated with them. Some common list methods are: - len(), which tells you the number of elements in a list. - count(), which looks for a specific element in a list, then returns the number of times that element is found. - reverse(), which reverses the order of the elements in a list. - sort() sorts the elements in a list. If this method has no argument, it sorts the elements into alphabetical order. - append() adds a new element to the end of a list.

Iteration in a Stack

Next, you will write a for loop that uses the range() function with the argument len(colors) to iterate through a stack. The loop will generate the correct number of iterator variables to loop once for each element in the list. The len() function tells you the number of elements in a list. The len(colors) code will generate the number of elements in the list, and this number will be used as the number of times the loop will iterate. The pop() function deletes an element at a specific index in the list. The print(colors.pop()) code will remove the last element in the list and return it by printing it in the Shell. This will happen once for each iteration in the loop, until all elements are removed from the list.

iteration

One pass of the coding sequence is called an iteration; when a set of instructions can be run multiple times throughout the program. good for: - write one set of instructions that operates on many sets of data, saving time and resources. - execute the programming loop repeatedly while records are read automatically. - identify errors in coding logic or in entered data.

The Range() Function

Programmers often use range() in control flow statements to set a limit on an iteration. The range() function uses integers to generate a list of numbers. It accepts many different types of arguments, but the simplest type is a single integer. If you use range() with a single integer as the argument, the function will generate a list of that number of integers, starting at 0 and going up to the integer just before the argument. The list will not include the function's number argument because Python starts counting at 0 instead of 1. For example, the range(10) function generates a list of ten integer values from 0 through 9.

def

Programmers use def when defining a function.

The For Loop Iterator

Programmers use for loops when they know how many times they want a block of code to be repeated. The for loop uses a temporary variable called an iterator, which keeps track of how many times the for loop has iterated. In Python, for loops usually follow this format, where i is the iterator variable and v is the value that ends the loop. The value of i increases with each iteration of the for loop until it equals v, the loop-ending value, at which point the loop ends and the interpreter goes to the next line of code after the loop.

Function Arguments (in python)

Programmers use function arguments to call, or execute, functions. You can call a function by using the following types of formal arguments: - required arguments. - keyword arguments. - default arguments. - variable-length arguments.

break statement

Python. stops the current loop, used to exit the loop completely. Resumes execution at the next statement, used when an external condition has been triggered. can be to exit while loops and for loops.

about: Compilers , in depth

Software app, translates (whole) high-level lang into binary comp machine lang., so that new, tranlsated, lang. can now be excecuted anytime during the running of the program.

Key tools of IDEs

Source code editor - aka text editor, used to write, modify, and save code. this is the main tool. Build automation - construct a program by writing directions for repetitive tasks. Compiler - translated programming language into computer language, also debugs. Interpreter - translates programming language into machine language without its being compiled. Debugger - test a program one step at a time to find & fix errors.

Function Definition Syntax

Syntax refers to the rules for structuring and formatting code so that programs can compile and run correctly. If a function is not written and formatted correctly, Python will not be able to run it successfully. The basic format of a Python function definition looks like this: def functionName( arguments ):statement1statement2statement3 The first line names the function and its arguments, while the lines underneath describe the action or actions that the function will execute to complete its task.

The Testing Cycle

Testing software code is an iterative process. This means you will go through the steps in the process as many times as it takes until the outcome is the one you desire. The testing cycle is a process involving: 1. Reproducing and diagnosing the error 2. Making a fix 3. Testing the fixed code The goal is error-free code.

Adding an Elif Statement

The Elif statement is short for "else if," and it lets you add another condition to an If statement. The Elif statement requires a condition, just like the If statement does. You can have as many Elif statements as needed

bits

The data in a computer is made up of a string of individual on and off switches known as bits. (The computer understands the on and off bits. You understand the words on the screen. In this way, humans and computers can communicate with each other.)

Array Indices

The fact that arrays can and often do have more than one dimension allows programmers to assign attributes to the elements and perform more sophisticated operations. In computer science, an array is stored so that the position of each element can be computed from its index. In a one-dimensional array or list, the index is a single integer, and the first position is always 0. In an array with two dimensions, the index is represented as a coordinate pair [x, y] known as a tuple, and the first index position is represented as [0, 0]. Programmers refer to more than one index as indices.

Function Header and Statements

The first line of the function definition is the header. The header contains the word def, which is a Python keyword used in defining a function, followed by the function's name, its arguments in parentheses, and a colon. Remember, the arguments are the input values that the function needs to do its work. You must separate multiple arguments with commas, like this: def functionName( argument1, argument2, argument3 ): Under the header are statements, which are lines of code describing the actions that the function will execute, in the order in which the actions must be executed. Each statement goes on its own line and must be indented four spaces so that Python will recognize that the statement is part of the function definition. TIP: In the Python IDLE, the TAB key is set by default to insert four spaces.

SHORT SUMMARY OF LAST FEW

The for loop can iterate over many items in a ✔ list.function.variable.loop index. The for loop looks for the ✔ first variableset variablefunctionloop index in the sequence and continues until the set variable✔ last variablesequence variableloop index in the list is complete. The ✔ sequence indexfunction indexloop indexvariable index uses a built-in function called length, or len(), which provides the total number of elements in the ordered list of elements as well as the range.

Iteration in a Queue

The pop() function works best when you need to remove the last element in a list, as in a stack. However, you can use pop() to remove the first element in a list to treat the stack like a queue. The first element in the list is at index 0. When you write pop(0) to remove the element at index 0, all of the other elements then get renumbered at new positions so that the next element in the list moves up to index 0, and so on through the entire list. Next, you will use the pop(0) function to use a list as a queue. Then you will learn about a better way to use a queue.

Deques

You can create a deque from a list by including the list as the deque() function's argument. For example, a variable named animals could be defined and given a deque data type as its value. The deque is made up of a list, like this: animals = deque(['cat', 'dog', 'bird'])

Using the Range() Function in a For Loop

You can use a for loop with the range() function to control how many times a loop will iterate. The integers generated by the range() function can be used to set the iterator variable's value for each cycle. In Python programming, the variable i is often used as a temporary iterator variable, but a for loop with the range() function could use any temporary variable name. When combined with the range function in a for loop, the i variable is automatically assigned the value generated by range(). The value of variable i changes as the loop iterates and the range() function generates different integers.

Variables and Naming Conventions

You learned that variables are useful tools in programming for naming and referring to specific values in code. Variables make code more readable to humans. To encourage consistent coding, Python has recommended naming conventions, or syntax, for naming variables. The = sign, or assignment operator, is used to assign a value to a variable. Values of any type can be assigned to a variable.

Using Variables in Operations

You learned that, in Python, values are assigned to variables using the = operator in the form of variable_name = value. Values come in different data types, including strings, integers, and floating point numbers. Python calculations can be done using values or using variables that represent values. An error will occur if you try to add a string to an integer.

data structure/s' types -Lists and Arrays

a data structure is a group of elements or objects that are arranged sequentially. - list ; most common, elements are organized sequentially in one dimension. - array ; data structure with two or more dimensions is called an array.

infinite loop

aka endless/continuos loop. Statement that provvides continuous repetition; computer will continue performing the action indefinitely because the statement condition never resolves to be false. A programmer can stop an infinite loop by entering CTRL+C. Programmers sometimes use infinite loops to test coding conditions or run demonstrations. Otherwise, infinite loops are rarely used.

code

also called: source code, is a set of instructions, writtten by a programmer, that is used by a computer to perform a task. Two basic components of code: procedures and functions.

Integrated Development Environments (IDEs)

are coordinated software program-writing packages. IDEs provide software developers with interactive programming tools and a work environment in which to use them. Combines software tools to write a program in one integrated package, all is simplified into one, easier to spot errors, automates repetitive tasks, common source for writing & linking code.

Hexadecimal Number System

base-16 systems that uses 16 digits made up of the numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, and the letters A, B, C, D, E, F. The 16 symbols that make up the hexadecimal number system are known as hex digits. Entering these numbers in hexadecimal numeric representation converts this: 48 45 4C 4C 4F To this: H E L L O At the machine level, the hexadecimal code will be converted and read in binary form. Programmers use hexadecimal numeric notation instead of binary because the combination of letter and numbers results in codes that are easier to remember than long strings of 0s and 1s.

Octal Number System

base-8 number system that uses the eight digits 0, 1, 2, 3, 4, 5, 6, and 7. Entering these numbers in octal numeric representation converts from this: 110 105 114 114 117 To this: H E L L O At the machine level, the octal code will be converted and read in binary form. Programmers use octal numeric notation instead of binary because the results are shorter, thus easier to use. For instance, it is easier to type 110 for H than it is to type 01001000.

for loop

can iterate over many items in a list or sequence. Used to repeat a piece of code a set number of times. "evaluates the list or sequence to find the first variable item, then continues through the list until it has found all of the variables." (?)

if-statement

common conditional ; statement where if one or more conditions is true, then the program will run a block of code in general, If statements follow this pattern: -If the conditional requirement in the If statement is True, then do something. -If the condition in the If statement is False, then nothing happens; that is, the block of code is skipped.

Else statements

contains the block of code to be excecuted if the answ to a the If statement is fasle or zero. syntax for Else in Python: if expression: statement(s) else: statement(s)

closed course IDEs / aka proprietary IDEs

devlpd & owned by comp. license that prevents the source code from being inspected or modified, requires fee.

Default Arguments

does not need to be specified. It assumes a default value if a value is not provided in the function call for that argument.

data structure/s' access methods - Stacks and Queues

elements can be arranged so that they can be accessed in specific ways. - stack ; is known as "last in, first out," or LIFO. - queue ; think of this as "first in, first out," or FIFO.

pass statement

exit statement used when programmer does not want anycode to execture but wants to keep that place in the code for future development, used often as a placeholder. It is a null statement.

insert(), remove(), and pop() Methods

insert() adds a new element by putting it into the list at a specific index. remove() searches for a specific element, and then deletes the first one it finds. pop() deletes an element at a specific index in the list. While deleting the element, this method also returns the element value. If you do not give the pop() method an argument for the index you want to remove, it will delete and return the last element in the list.

A function

is a (reusable) block of code that performs a single task, but it also returns a value - the result of a function.

A procedure

is a (reusable) block of code that performs a single task. Programmers are able to reuse a procedure multiple times, thus saving time. In Python, procedures are defined as follows:FunctionDefinition ::= defName (Parameters):Statements

binary number system

is a base-2 number system that represents numerical or alphabetical values using the digits 0 and 1. Bits are grouped in units that are multiples of 4. In ASCII, the American Standard Code for Information Interchange, each group of 8 bits represents a number or letter. Entering these strings of 0s and 1s in binary notation converts this: 01001000 01000101 01001100 01001100 01001111 To this: H E L L O

while loop

is a looping construct (used in Python). It continues to repeat until the expression becomes false, therefore the expression must have a t or f value. syntax: while expression: statement(s)

loop statement

is a statement that causes a section of code to be repeated a certain number of times. The repetition will continue as long as the condition in the code is true. When the condition becomes false, the loop will end and the program will continue on to the next block of code.

A parameter

is a variable (in a subroutine) that refers to a piece of data; the argument. The term argument is often used interchangeably with parameter, although parameter can also refer to any value that can be changed.

An argument

is the actual data that gets passed into the parameter. The relationship between a parameter and an argument can be compared to the relationship between a variable and a constant.

A data type

is the kind of value that a variable can hold. Each data type has a unique set of characteristics & stores data in a specific way.

decimal number system

is the one most commonly used by people in everyday settings. It is a base-10 number system that uses ten symbols made up of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. At the machine level, the decimal code will be converted and read in binary form. Programmers use decimal numeric notation because it is familiar, making it easier to use and to read. converts this: 72 69 76 76 76 To this: H E L L O

The return statement

is used to exit a function and pass back a value if necessary,will give you the option of passing back an expression to the person calling or running the program.

Iteration aka loopings

iteration means to repeat a set of actions until the program reaches a target. Iteration is commonly called looping because the program checks whether the condition for the iteration exists, runs the iteration, and then loops back to the beginning of the statement to check again. Once the loop condition is no longer true, the program goes on to the next part of the code. Iteration, or looping, is an example of a programming technique called control flow

open source IDEs

license that makes source code available to inspect & modify, works with multiple high-lev-langs.

Computer numbering systems

make use of an agreed-upon code to assign meaning to the pattern of on or off bits. You create code using commands and other words.

Fixing & Verifying code

process of correcting errors, followed by verifying there are no new errors

Control Flow Statements

programming technique, statements change the order in which lines of a program are run.

continue statement

python. exits loop then returns to beggining of loop (by rejecting remaining statements in current iteration of loop, then moving back to top) Used for while loops and for loops.

boolean operations

return a true or false value based on whether the compared values are alligned or not. with the operators AND and OR, a programmer can combine several comparisons logically into one boolean expression.

single-statement suites

similar to IF statements. Code is placed on one line. Useful for allowing programs to be smaller. "If the while cause is onny one line, it can go on the same line as the header." (?)

syntax

the rules for structuring and formatting code so that programs can compile and run correctly.

Elif statements

used to check multiple conditions and execute a block of code as soon as one of the conditions evaluates true. Syntax: if expression1:statement(s) elif expression2:statement(s) elif expression3:statement(s) else:statement(s) The Else statement at the end is optional. Without it, no action is taken if none of the statements is true.

IF statements

Aka: if then is a conditional statement that tests whether a condition following it is true or false. If statements, just like any statements, have syntax. if expression: statement(s) if number_of_snakes > 1:

Errors in Computer Programming

An error in computer programming is anything that causes a computer to return an unpredicted result or to crash, or fail to complete execution of the program. Errors can cause an error message to appear. They can also cause a program to halt during execution or return results that are incorrect or unexpected.

The Logic Error

A logic error in computer programming is a mistake in the program that does not cause the program to stop running, but it produces unintended results. This type of mistake does not give the correct instruction for the next step to occur while the program runs. It also usually does not cause an error message. Logic errors are easy to miss. These are the errors that allow your program to run from start to finish but return values that are wrong. The results are incorrect because the instructions were incorrect.

Run-Time Error

A run-time error in computer programming occurs when the program receives data in a form that was not anticipated while the programming is running. Three examples of this are when: -a user enters a numeric value when a text value was expected. - a user enters a text value when a numeric value was expected. - a user enters a negative number when a positive number was expected.

Catching Syntax Errors

Catching syntax errors starts during the development of the computer program and continues throughout the testing of the program. Compilers and interpreters help programmers catch syntax errors. A compiler translates the programming language into computer machine language before the software program is run. An interpreter translates the programming language into computer machine language while the program is running. Both compilers and interpreters usually have a way to highlight a line of code with a syntax error in it. Sometimes the highlighting happens as soon as the error is typed in. Compiler and interpreter software programs are usually part of integrated development environment programming software packages. A syntax error that occurs as the result of a variable name that is misspelled will not be highlighted. Errors that are caused by mistyping a numeric value such as 10000 when the intended amount is 1000 will also go uncaught.

"strongly typed" & variables and data types

If a programming language is strongly typed, the data type has to be stated before the variable can be used. For example, the program may specify that an integer must be declared, followed by a character. Example; Visual Basic and JavaScript.

Using Range() with More Than One Argument

If you use two arguments with the range() function, the function will generate a list of integers starting with the first number and ending at the second number - 1. For example, range(5, 11) generates the six integers from 5 to 10: 5, 6, 7, 8, 9, 10 A for loop using this range would iterate through the integers 5 to 10.

Syntax for the encode() Method

In the encode() method, the default encoding argument is "utf-8". A programmer could specify a different encoding system, but UTF-8 is the preferred system for most Internet and software uses. The second argument, errors = "strict", means that if there is an encoding error, Python will throw an exception called UnicodeError. This will alert the programmer that the input may not be a UTF-8 string at all. There are other possible values such as "ignore" and "replace", but it is best to stick with "strict" until you are an advanced programmer. Next, you will practice using the encode() string method in Python.

The decode() Method

Of course, Python includes a string class method to decode Unicode into text as well. The decode() method essentially reverses the operation of the encode() method. It operates on a Unicode value and returns a text string.

Addressing Logic Errors

Once the source of a logic error is discovered, it can be addressed by making a fix to the code. Addressing a logic error may require you to test different scenarios. It may require the use of debugging tools. Sometimes the original program needs to be changed to correct a logic error. You must consider whether your arithmetic operations are legal, your inputs are the types of inputs you anticipated, and the program flow is what you conceived when you wrote the conditional statements in your code. The code will be tested and retested until the modifications provide the desired results. It may take several cycles of testing and modifying the code.

Addressing Run-Time Errors

Once the source of a run-time error is discovered, the error can be addressed by: adding error routines that allow the program to execute fully even when unanticipated data is entered. creating error messages to alert the user to an error in data entry. creating controls in the program that ensure the input of proper data.

Finding Logic Errors

Programmers test programs with sample data sets to detect logic errors. When values output by a program differ from anticipated outputs, programmers check the code. To do so, they use a different sample data set and run the program to trace the source of the logic error. To assist in this process, most compilers and interpreters have a stepping function a way to run a program line by line and observe the current value of program variables. When an incorrect value is spotted, the programmer can zero in on the cause.

The encode() Method

Python has a class of methods called string methods because they operate on strings of text. The encode() method takes a text string and returns an encoded version of the string in UTF-8 octets. An efficient way to use this method is to declare a variable and assign the text string to be encoded as its value, and then write the encode() method to operate on the variable.

Run-Time Error Alerts

Run-time errors are hard to miss. These are the errors that crash your program and cause it to halt execution of the program. Because of this, it is vital that a programmer test the code before release by entering extreme values. Entering extreme values is one way to find an error. In a case where the number of minutes to be billed will be an input, this might mean: entering a value that is far larger than likely. entering a value that is 0. entering a value that is a negative number. `entering a value that is not numeric.

Syntax Error Alerts

Some types of syntax error alerts are: lines of code that appear highlighted when they are entered. unanticipated values for variables. results that do not match programmer expectations or intentions.

ASCII (first character encoding system)

The American Standard Code for Information Interchange It defines numeric values between 0 and 127 for various characters only defines unaccented characters

The Popleft() Function

The deque class has a function called popleft(). It is a more efficient way to remove and return the first element in a list. You can use popleft() to return the first element in the deque object instead of using pop(0). Using popleft() and pop() together, you can make the program return elements from the start or end of a deque object. In this way, you can take advantage of the efficiencies of a double-ended queue.

Operators

The programming objects that are able to control a value

Finding Run-Time Errors

The source of a run-time error can be discovered by the programmer who wrote the code or by quality assurance specialists who test the code. It can also be discovered by issuing a Beta version of the program that is nearly ready to release to the public.

bit pattern

a specific sequence of binary digits

8-Bit Systems - Unicode - UTF-8 ("and the move toward unified encoding")

in the 1980s, the arrival of 8-bit personal computers meant that bytes could hold numeric values from 0 to 255. ASCII codes only went up to 127 late '80s, developers from Xerox and Apple worked on the explicit goal of unifying the various encoding systems into one universal character set Unicode, a character encoding system that can represent text written in all of the world's languages and scripts. Unicode assigns a unique code point, an integer value denoted in base 16, to each character in the world's languages. whateverthef**k: "UTF-8, which stands for Universal Character Set (UCS) Transformation Format - 8-bit, is an encoding that can represent every character in the Unicode character set. UTF-8 has become the dominant form of Unicode character encoding for web and e-mail programs. UTF-8 uses one 8-bit byte, called an octet, for ASCII characters, and between one and four octets for other characters. One-to-one correspondence with ASCII characters makes any valid ASCII text automatically valid as UTF-8-encoded Unicode too."

Character encoding

is a system in computer programming that pairs each character in a given set, such as a language, with a code. can be a bit pattern, a sequence of numbers, or electrical pulses.

The three most common types of computer programming errors

syntax errors, which are due to misuse of the proper syntax in the programming language. run-time errors, which are due to mistakes in the execution of commands; these cause the running of the program to halt. logic errors, which are due to a mistake in the program that does not cause the program to stop running and instead produces unintended results.

reference materials

usually online help, used manuals, tutorials that; might contain tips, tricks, sample code, or guides.

loop

when a sequence is excecuted multiple times.


Conjuntos de estudio relacionados

APUSH chapter 13 test multiple choice

View Set

Powerpoint 2019/365 - Concept Review 1

View Set

NUR326 Mental Health Medications

View Set

Chapter 11, The Health Care Delivery System

View Set

Chapter 14: Environmental Liability Insurance

View Set

Abeka Vocabulary Spelling Poetry V Quiz 1A

View Set

Introduction to the Quadratic Formula

View Set

BAS 282: Global Marketing: SmartBook

View Set