Python Chapter 2

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Math expressions

Performs a calculation and give a value 12 + 2

Comments

Short notes placed in different parts of a program, explaining how those parts of the program work. Ignored by the python interpreter, they are intended for any person reading a program's code, not the computer

Parallelograms

Used as INPUT symbols and OUTPUT symbols. They represent steps in which the program reads input or display output.

Rectangles

Used as PROCESSING symbols. They represent steps in which the program performs some process on data, such as a mathematical calculation

String literal

When a string appears in the actual code of a program, it is a string literal. Must be enclosed in quote marks

References

When a variable represents a value in the computer's memory, we say that the variable references the value

Calling

When programmers execute a function, they say that they are calling the function

Assignment statement

You use an assignment statement to create a variable and make it reference a piece of data. Ex: age = 25

line continuation

\

named constant

a name that represents a value that cannot be changed during the program's execution

A magic number is

a number that is mathematically undefined

numeric literal

a number that is written into a program's code

escape character

a special character that is preceded with a backslash \ \n causes output to be advanced to the next line \t causes output ot skip over the next horizontal tab position \' causes a single quote to be printed \'' causes a double quote mark to be printed \\ causes a backslash character to be printed

format specifier

a string that contains special characters specifying how the numeric value should be formatted '.2f'

A(n) --- is a set of well-defined logical steps that must be taken to perform a task

algorithm

mixed-type expression

an expression that uses operands of different data types

magic number

an unexplained value that appears in a program's code

An ___ makes a variable reference a value in the computer's memory

assignment statement

Variable naming rules

cannot contain spaces cannot use python's key words uppercase and lowercase matters etc...

short notes placed in different parts of a program explaining how those parts of the program work

comments

Data types

different types of numbers are stored and manipulated in different ways, python uses data types to categorize values in memory

A string literal in Python must be enclosed in

either single-quotes or double quotes

new line character

end=' '

Invalid

example: the variable that is receiving the assignment must appear on the left side of the =operator invalid: 72 = amount

If you print a variable that has not been assigned a value, the number 0 will be displayed.

false

Programmers must be careful not to make syntax errors when writing pseudocode programs.

false

Variable names can have spaces in them.

false

Suppose the following statement is in a program: price = 99.0. After this statement executes, the price variable will reference a value of this data type.

float

This built-in function can be used to convert an int value to a float.

float( )

A --- is a diagram that graphically depicts the steps that take place in a program

flowchart

how do you suppress the print function's ending newline?

if you do not want the print function to start a new line of output when it finishes displaying its output, you can pass the special argument end = ' ' to the function

This built-in function can be used to read input that has been typed on the keyboard.

input( )

#

marks the beginning of a comment in Python

a ___is a name that represents a value that does not change during the program's exceptional execution

named constant

what are three advantages of using named constants

named constants make programs more self-explanatory widespread changes can easily be made to the program they help to prevent the typographical errors that are common when using magic numbers

In the expression 12 + 7, the values on the right and left of the + symbol are called

operands

An informal language that has no syntax rules, and is not meant to be compiled or executed is called: pseudocode

pseudocode

%

remainder operator. also known as the modulus operator

no space between lines

sep='' can add a symbol in the middle of the quotes

A --- is a single function that the program must perform in order to satisfy the customer

software requirement

str

storing string in memory

A --- is a sequence of characters that is used as data

string

//

this operator performs integer division

In Python the first character of a variable name cannot be a number.

true

In a math expression, multiplication and division takes place before addition and subtraction.

true

A --- is any hypothetical person that is using a program and providing input for it

user

A --- is a storage location in memory that is represented by a name

variable

Assignment operator

variable = expression. the equal sign is known as the assignment operator

float

when a real number is stored in memory ex: 1.5, 3.14159, 5.0

Garbage collection

when a value in memory is no longer referenced by a variable, the python interpreter automatically removes it from memory through a process known as garbage collection

int

when an integer is stored in memory it is classified as an int ex: 7, 124, -9

17 = x

will cause an error in Python, must be in x = 17 order

how can you change the character that is automatically displayed between multiple items that are passed to the print function?

you can pass the argument sep= to the print function, specifying the desired character

Exception

An unexpected error that occurs while a program is running, causing the program to halt if the error is not properly dealt with

Input

Any data that the program receives while it is running. Like data that is typed on a keyboard. Once input is received, the results of the process are then sent out of the program as output

User

Any hypothetical person that is using a program and providing input for it. Sometimes called the end user

Who is a programmers customer?

Any person, group, or organization that is asking you to write a program

Ovals

Appear at the top and bottom of the flowchart. Terminal symbols. The START terminal symbol marks the program's starting point, and the END terminal symbol marks the program's ending point.

Program Development Cycle

Design the program Write the code Correct syntax errors Test the programs Correct logic errors

Pseudocode

Fake code. Informal language that has no syntax rules and is not meant to be compiled or executed. Instead programmers use pseudocode to create models, or 'mock-ups' of programs

Argument

Inside the parentheses, you type an argument, which is the data that you want displayed on the screen. Like Hello World. Quote marks specify the beginning and the end of the text you wish to display

A ___ error does not prevent the program from running, but causes it to produce incorrect results

Logic

value1 = 99 value2 = 45.99 value3 = 7.0 value4 = 7 value5 = 'abc'

1 = int 2 = float 3 = float 4 = int 5 = str

End-line comments

A comment that appears at the end of a line of code. It usually explains the statement that appears in that line

Flowchart

A diagram that graphically depicts the steps that take place in a program. There are three types of symbols in the flowchart: ovals, parallelograms, and a rectangle

nested function

A function's parameters, plus any variables that are bound (by assignment or by other binding statements, such as def) in the function body, make up the function's local namespace, also known as local scope. Each of these variables is known as a local variable of the function.

Variable

A name that represents a value stored in the computer's memory. Like TAXA CAN REPRESENT THE VALUE IN MEMORY.

Function

A piece of rewritten code that performs an operation. Like print('')

String

A sequence of characters that is used as data is called a string. 'Hello World'

Algorithm

A set of well-defined logical steps that must be taken to perform a task

What is a software requirement?

A single function that the program must perform in order to satisfy the customer.

This operator performs division, but instead of returning the quotient it returns the remainder.

%

an operator that raises a number to a power

**

symbols

+ - * / (floating point number) // (whole number division) % (remainder, divides one number by another and gives the remainder)

string concatenation

+ so the print function can span multiple lines it joins the string together


Ensembles d'études connexes

Saunders: Developmental Stages: End of Life

View Set

Chapter 20: The Progressive Era, 1890-1920

View Set

OMNI Air International City Codes

View Set

Chapter 65 med surg (Assessment of function worksheet)

View Set

B AD 4013 (Bolino) Exam 1 Articles

View Set

Sullen, Quiescence, Meticulous, Inclined, Flippant, Erudite, Dogmatic, Daunting, Coerce, Vindication

View Set