Python Chapter 2

Ace your homework & exams now with Quizwiz!

A comment in Python is denoted by the ____ character.

#

This symbol marks the beginning of a comment in Python

#

modulus operator

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

Remainder operator

%, Divides one number by another and gives the remainder

This is an operator that raises a number to a power.

**

_________ is a Python math operator which raises a number to a power

**

Exponent operator

**, Raises a number to a power

Multiplication operator

*, multiplies one number by another

Addition Operator

+ Adds two numbers

Subtraction operator

-, subtracts one number from another

Division operator

/, Divides one number by another and gives the result as a floating-point number

This operator performs integer division

//

Integer division operator

//, Divides one number by another and gives the result as an integer

In Python, the value of 9 % 2 =

1

In Python, the value of 12 / 2 - 4 =

2.0

In Python, the value of 14 / (11 - 4) =

2.0

In Python, the value of 6 + 3 * 5 =

21

In Python, the value of (6 + 2) * 3 =

24

In Python, the value of 9 + 14 * 2 - 6 =

31

Variable names which would be illegal in Python

3dGraph, Mixture#3

In Python, the value of 9 // 2 =

4

In Python, the value of 9 + 12 * (8 - 3) =

69

software requirement

A single task that a program must preform in order to satisfy the customer

exception

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

mixed-type expression

An expression that contains operands of different data types; also called mixed mode expression

Operator Precedence

Exponentiation **; Multiplication, division, and remainder * - / - // - %; Addition and subtraction + -

/* is a character used for writing comments in Python

False

Variable names can have space

False

// operator

When the result is positive, it is truncated, which means that its fractional part is thrown away. When the result is negative, it is rounded away from zero to the nearest integer

The five stages of the Program Development Cycle are: Design the program, ___________, Correct Syntax Errors, _____________, Correct logic errors.

Write the code, Test the code

float(item)

You pass an argument to the float( ) function and it returns the argument's value converted to a float.

int(item)

You pass an argument to the int() function and it returns the argument's value converted to an int.

Line continuation character

a backslash (\)

flowcharts

a diagram that graphically depicts the steps that take place in the program.

logic error

a mistake that does not prevent the program from running but causes it to produce incorrect results

variable

a name that represents a value stored in the computer's memory

numeric literal

a number that is written into a program's code

function

a piece of prewritten code that performs an operation

math operators

a programmer's tools for performing calculations

string

a sequence of characters that is used as data

algorithm

a set of well-defined steps for performing a task or solving a problem

escape character

a special character that is preceded with a backslash (\), appearing inside a string literal

psuedocode

an informal language that has no syntax rules and is not meant to be compiled and executed, but instead used to create models, or mock-ups, of programs

horizontal tab

appears after every eighth character

end-line comment

appears at the end of a line of code

string concatenation

appends one string to another: print('This is ' + 'one string.')

The equal sign (=) in Python is known as the _______

assignment operator

A(n) ________ makes a variable reference a value in the computer's memory.

assignment statement

What does a professional programmer usually do first to gain an understanding of a problem?

by working directly with the customer.

data types

categorize value in memory

escape character \\

causes a backslash character to be printed

escape character \"

causes a double quote mark to be printed

escape character \'

causes a single quote mark to be printed

escape character \t

causes output to skip over to the next horizontal tab position

escape character \n

causes the output to be advanced to the next line

Multiple arguments to a function are separated by

commas

format specifier

contains special characters specifying how the numeric value should be formatted:

assignment statement

create a variable and make it reference a piece of data. (age = 25) (variable = expression)

argument

data passed to a function.

Input

data the program receives

print function

displays output in a Python program.

If you want a string literal to contain either a single-quote or an apostrophe as part of the string, you can enclose the string literal in ______ marks.

double-quote

A string literal in Python must be enclosed in

either single-quotes or double-quotes

If you do not want the print function to start a new line of output when it finishes displaying it output, you can pass the special argument:

end=' '

An unexpected error that causes a running program to halt if it is not solved properly is called a(n)

exception

debug

find and correct coding errors.

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

When an operation is performed on two float values, the result will be:

float

A numeric literal that is written with a decimal point is considered a(n)

float (1.5, 3.14159, 5.0)

What is the difference between floating-point division and integer division?

floating point division produces a floating point result. integer division produces an integer rounded to a number closest to 0 as output.

format specifier setting decimal precision to two spaces:

format(12345.6789, '.2f')

A ______ is a piece of prewritten code that performs an operation

function

When a value in memory is no longer referenced by a variable, it is automatically removed through a process known as _____

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

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

input()

Computer programs typically perform what three steps?

input, process, output

When an operation is performed on two int values, the result will be:

int

A numeric literal that is written as a whole number with no decimal point is considered a(n):

int (7, 124, -9)

When an integer is stored in memory, it is classified as a(n) _______, and when a real number is stored in memory, it is classified as a(n) _______.

int, float

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

software requirement

A ______ is a sequence of characters.

string

calling

term used by programming to indicate the execution of a function

ovals in flowcharts

terminal symbols used to mark the starting and ending points of a program in a flowchart

When an operation is performed on an int and a float:

the int value will be temporarily converted to a float and the result will be a float.

Python also allows you to enclose string literals in ____________________ when the string contains both single and double quotes.

triple quotes (either """ or ''')

Variable reassignment

typically means to change the value of a variable based on its current value.

Variable names which would be legal in Python:

units_per_day, dayOfWeek, June1997

parallelograms in flowcharts

used as input and output symbols representing steps in which the program reads input or displays output

rectangles in flowcharts

used as processing symbols representing the steps in which the program performs some process on data, such as a mathematical calculation.

a _____ is any hypothetical person using a program and providing input for it.

user

A ______ is a name that references a value in the computer's memory

variable

string literal

when a string appears in the actual code of a program

Nested function calls

where one function calls another

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

True

Multiplication, floating-point division, integer division, and remainder operators have the same precedence

True

The float() function can be used to convert an int value to a float

True

You cannot use one of Python's key words a variable name.

True

The process of designing a program:

Understand the task the program is to perform, and Determine the steps that must be taken to perform the task.

When operators share an operand, the operator with the higher ______ is applied first.

precedence

print statement

print('string expression')

floating point as percentage multiplied by 100

print(format(0.5, '%'))

floating point as percentage with 0 as precision

print(format(0.5, '.0%'))

comma separator in format specifier

print(format(12345.6789, ',.2f'))

format specifier including a minimum field width

print(format(12345.6789, '12,.2f'))

formatting in scientific notation

print(format(12345.6789, 'e')) OR print(format(12345.6789, '.2e'))

integer printed with a comma separator

print(format(123456, ',d'))

integer printed with a comma separator in a field that is 10 spaces wide

print(format(123456, '10,d'))

integer printed in a field 10 spaces wide

print(format(123456, '10d'))

integer printed with no special formatting

print(format(123456, 'd'))

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

pseudocode

Tools used by programmers to create models of programs

pseudocode and flowcharts

exponent operator

raises a number to a power

input function

reads a piece of data that has been entered at the keyboard and returns that piece of data, as a string, back to the program; variable = input(prompt)

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

references

item separator

sep=' ' (print('one', 'two', 'three', sep=' '))

character used to enclose string literals

single-quotation or double-quotation marks

You can use __________ marks to enclose a string literal that contains double quotes as part of the string.

single-quote

Who is a programmer's customer?

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

What is a format specifier and why is it used?

Because numbers are used in a variety of ways, such as in percentages and currency, it is used to output numeric data in a form that is relevant to the program.

Output

Data that has been processed into a useful format.

The Program Development Cycle

Design the program, Write the code, Correct syntax errors, Test the program, Correct logic errors; back to beginning

operands

The values on the left and right of the math operator

An expression that uses operands of different data types is called a ______

mixed-type expression

Variable naming rules

no Python key words, cannot contain spaces, first character must be a letter or underscore, preceding characters can be letters, numbers, or underscores, and uppercase and lowercase characters are distinct.

newline character

not seen, but causes the output to advance to the next line.

comments

notes of explanation that document lines or sections of a program. Part of the program, but ignored by the Python interpreter. Intended for people who may be reading the source code.

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

operands

symbols in flowcharts

ovals, parallelograms, and rectangles

math expression

performs a calculation and gives a value


Related study sets

Ch 2, California Real Estate Principles 15th Edition Walt Huber

View Set

Biology Concepts and Applications Chapter 2

View Set

Islamic Quiz-100 Questions and their Answers

View Set