zybook chapters 1-8 python Questions and Complete Solutions Graded A+
computer program - Answer: Consists of instructions that a computer executes (or runs), like multiplying numbers or printing a number to a screen.
task decomposition - Answer: Means to reduce a complex task into simpler basic steps, making the whole task easier to solve.
algorithm - Answer: A recipe or a methodical step-by-step procedure to perform a task.
computational thinking - Answer: Evaluating a problem's most basic parts and then creating an algorithm to solve that problem is commonly known as
Python interpreter - Answer: An application that can be used on various operating systems, including Microsoft Windows, Linux, and MacOS.
interactive interpreter - Answer: A program that allows the user to execute one line of code at a time.
code - Answer: A common word for the textual representation of a program
line - Answer: A row of text
prompt - Answer: Indicates the interpreter is ready to accept code ""
statement - Answer: A program instruction
expression - Answer: code that returns a value when evaluated;
variables - Answer: Named references to values stored by the interpreter.
assignment - Answer: Creates a new variable by using the = value
comments - Answer: used to explain portions of code to a human reader. "# PA1"
print() - Answer: displays variables or expression values
string literal - Answer: Text enclosed in quotes is known as this. ('hello world')
new line character - Answer: A new line can also be output by inserting n.
ex: "1/n2/n3"
input - Answer: Reads text entered by the user, and assigns the entered text to a variable. Causes the interpreter to wait until the user has entered some text and has pushed the return key.
string - Answer: Always surrounded by single or double quotes, for example 'Hello' or "#Goodbye# Amigo!".
type - Answer: Determines how a value can behave
int() - Answer: used to convert that string to the integer
syntax error - Answer: Violates a programming language's rules on how symbols can be combined to create a program.
runtime error - Answer: a program's syntax is correct but the program attempts an impossible operation, such as dividing by zero or multiplying strings together
crash - Answer: Abrupt and unintended termination of a program
logic error - Answer: A logically flawed program. It works but the output is not correct for the given goal for the program.
bug - Answer: another name for a logic error
integrated development environment - Answer: Code development. A way to create programs and test them all in one.
bit - Answer: 0s and 1s (another way to call "binary numbers")
processor - Answer: created to process (aka execute) a list of desired calculations
instruction - Answer: each calculation output from processors
memory - Answer: circuits that can store 0s and 1s in each of a series of thousands of addressed locations
program, application, or "app" - Answer: The programmer -created sequence of instructions
machine instructions - Answer: Instructions represented as 0s and 1s
executable program - Answer: a sequence of machine instructions
assembly - Answer: created programs called assemblers to automatically translate human readable instructions
high-level languages - Answer: programmers created this to support programming using formulas or algorithms, so a programmer could write complex formulas
compilers - Answer: programs that automatically translate high-level language programs into executable programs.
Input/output devices - Answer: input device:
keyboard
output device:
screen or "monitor"
Storage - Answer: a "disk" is used for this. Can store any type of data.
Memory - Answer: Stored on RAM
Operating system - Answer: allows a user to run other programs and which interfaces with the many other peripherals
clock - Answer: the rate that a processor can execute a program
transistors - Answer: after computers were first invented and occupied entire rooms, engineers created smaller switches called THIS
Integrated circuit - Answer: transistors were intergrated into this
moores law - Answer: the process of continuously making transistors in processors smaller
machine language - Answer: two character alphabet using 0's and 1's
Machine instructions - Answer: sequence of instruction using 0's and 1's
executable program - Answer: assembly of a program happens in this type of file ".exe"
scripting languages - Answer: programs without the need for compilation
script - Answer: a program whose instructions are executed by another program called an interpreter
backwards compatible - Answer: "being not able to run programs on later version of python"
open-source - Answer: meaning the community of users participate in defining the language and creating new interpreters, and is supported by a large community of programmers
object - Answer: programmers use this to represent a value
variable - Answer: used to remember a value for later use
name - Answer: What a programmer decides to call a variable
assignment statement - Answer: assigns the name on the left side to reference the value on the right side.
like "num_apples = ..."
Value - Answer: A value such as "20", "abcdef", or 55
type - Answer: The type of the object, such as integer or string
Identity - Answer: A unique identifier that describes the object.
type() - Answer: prints the type of an object
Mutability - Answer: indicates whether the object's value is allowed to change
id() - Answer: gives the value of an object's identity.
name, identifier, underscore - Answer: A name, also called an identifier, is a sequence of letters (a-z, A-Z, _) and digits (0-9), and must start with a letter. Note that "_", called an underscore, is considered to be a letter.
reserved words - Answer: Certain words, like "and" or "True" can not be used as names. Those words are part of the language and are called ...
ALSO CALLED KEYWORDS
PEP 8 - Answer: Python Enhancement Proposal
a document that outlines the basics of how to write Python code neatly and consistently
float - Answer: an additional data type exists for floating-point numbers known as ...
floating-point literal - Answer: an integer with the fractional part added like "5.0 or 99.0"
scientific notation - Answer: written using an e preceding the power-of-10 exponent, as in 6.02e23 to represent 6.02x10^23
OverflowError, Overflow - Answer: occurs when a value is too large to be stored in the memory allocated by the interpreter.
expression - Answer: A combination of items such as variables, literals, and operators that evaluates to a value.
literal - Answer: a specific value in code like 2 or "abc".
operator - Answer: a symbol for a built-in language calculation like + for addition
Arithmetic operators - Answer: + addition
- subtraction and negation
* multiplication
/ division
// floored division
% modulo (remainder)
** exponentiation
unary operator - Answer: Used to negate a value
modulo operator - Answer: evaluates to the remainder of the division of the two integer operands
Ex:
23 % 10 evaluates to 3 (because 23/10 is 2 with a remainder of 3)
precedence rules - Answer: An expression is evaluated from left-to-right by the interpreter, using the order of standard mathematics known as
unicode - Answer: represents every possible character as a unique number
also known as code print
escape sequence - Answer: Upon reaching a backslash, the interpreter recognizes that item as the start of a special character's two-item sequence and then looks at the next item to determine the special character. The two-item sequence is called an ...
raw string - Answer: Escape sequences can be ignored using a ...
A ... is created by adding an 'r' before a string literal
ord() - Answer: returns an encoded integer value for a string of length one.
chr() - Answer: returns a string of one character for an encoded integer.
string - Answer: variables that store a sequence of characters
sequence type - Answer: a type that specifies a collection of objects ordered from left to right.
index - Answer: The position of a character in a string
len() - Answer: used to find the length of a string
brackets [ ] - Answer: A programmer can access a character at a specific index by appending "this"
for example:
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
print(alphabet[0], alphabet[1], alphabet[25])
output is "A B Z"
string concatenation - Answer: A program can add new characters to the end of a string in a process known as ...
Containers - Answer: contain references to other objects instead of data
list - Answer: surrounds a sequence of variables or literals with brackets [ ]
element - Answer: Any type of items inside a container
index - Answer: ex: "A list is also a sequence, meaning that the contained elements are ordered by position in the list. The first item in the list has a position, or index, of 0, the next item has an index of 1, and so on. An empty list can be created by using empty brackets, as in my_list = [ ]."
append() - Answer: Lists are mutable, meaning that a programmer can add and remove elements from a list as needed. New elements are added to a list using the ... method
method - Answer: instructs an object to perform some action, and is executed by specifying the method name following a "." symbol and an object.
pop( ), remove( ) - Answer: Elements can be removed using the pop( ) or remove( ) methods.
sequence-type methods - Answer: built-in functions that operate on sequences like lists and strings.
tuple - Answer: behaves similar to a list but is immutable - once created the tuple's elements can not be changed.
Values do not change in this sequence type
dict - Answer: maps unique keys to values
key - Answer: like the word "cat" from the English dictionary
comes after "dict" object type
value - Answer: describes some data associated with a key, such as a definition.
braces - Answer: surrounds key:value pairs
key:value pairs - Answer: comprises the dictionary contents
KeyError - Answer: "Unlike lists, which order elements according to a left-to-right positioning in a sequence, dictionaries maintain no such ordering of its entries. To access an entry, the key is specified in brackets [ ]. If no entry with a matching key exists in the dictionary, then a KeyError runtime error occurs and the program is terminated."
del - Answer: used to remove entries from a dictionary
Numeric types - Answer: supports the normal mathematical operations such as addition, subtraction, multiplication, and division, among others
Sequence types - Answer: containers for collections of objects ordered by position in the sequence, where the first object has an index of 0 and subsequent elements have indices 1, 2, etc.
ex: string, list, and tuple
mapping type - Answer: The only mapping type in Python is the dict type. Like a sequence type, a dict serves as a container.
type conversion - Answer: a conversion of one type to another, such as an int to a float.
implicit conversion - Answer: automatic conversion
The interpreter automatically performs common conversions between numeric types like int and float.
String formatting expressions - Answer: allows a programmer to specify a string that has placeholders for variables' values.
conversion specifiers - Answer: defines the type of value being printed.
math module - Answer: supports such advanced math operations in python
module - Answer: Python code located in another file.
function - Answer: a list of statements that can be executed simply by referring to the function's name.
function call - Answer: The process of invoking a function
argument - Answer: The item passed to a function
Branching - Answer: directs a program to execute either one group of statements or another
relational operators and equality operators - Answer: a b a is less-than b
a b a is greater-than b
a = b a is less-than-or-equal-to b
a = b a is greater-than-or-equal-to b
a == b a is equal to b
a != b a is not-equal to b
boolean - Answer: when an operand evaluates to a value meaning true or false
operator chaining - Answer: "For example, a b c determines whether b is greater-than a but less-than c. Chaining performs comparisons left to right, evaluating a b first. If the result is true, then b c is evaluated next. If the result of the first comparison a b is false, then there is no need to continue evaluating the rest of the expression. Note that a is not compared to c."
elif - Answer: requires more than two branches
nesting - Answer: The sub-statements following an "if" or "else" may include even more if-else statements, a technique commonly known as ...
boolean operator - Answer: can be used to combine multiple expressions into a single logical expression
and (boolean op) - Answer: Boolean AND: True when both operands are True
or (boolean op) - Answer: Boolean OR: True when at least one operand is True.
not (boolean op) - Answer: Boolean NOT (opposite): True when the single operand is False (and False when operand is True).
boolean expression - Answer: An expression using Boolean operators
precedence - Answer: determines the order that Boolean expression operate
"in" and "not" as membership operators - Answer: The in and not in operators, known as membership operators, yield True or False if the left operand matches the value of some element in the right operand, which is always a container.
substring - Answer: used to check whether a string is a matching subset of characters, of a larger string.
identity operator "is" - Answer: checks whether two operands are bound to a single object.
"is not" (identity op) - Answer: gives the negated value of 'is'. Thus, if x is y is True, then x is not y is False.
code block - Answer: a series of statements that are grouped together.
conditional expression - Answer: basically, its a statement that is done on one line instead of multiple. An example of this could be when you want to form an (if, else) statement in one expression.
ternary operation - Answer: A conditional expression that has three operands
loop - Answer: executes the same code over and over again as long as some condition is true
while loop - Answer: executes a block of code as long as the loop's expression is True
loop body - Answer: when the program reaches the while loop statement, and if the loop expression is True then the indented code block is executed
iteration - Answer: Each execution of the loop body
looping is also "this" in general
infinite loop - Answer: a loop that will always execute because the loop's expression is always True
Multi-line comment - Answer: ex:
"""
this program executes etc...
"""
A way to explain the program before presented to higher associate
loop variable - Answer: a variable to count the number of iterations
for loop - Answer: loops over each element in a container one at a time, assigning the next element to a variable that can then be used in the loop body.
reversed() - Answer: reverses the order of the elements.
range() - Answer: generates a sequence of numbers, starting at zero and ending before a value given inside the parentheses
nested loop - Answer: A loop that appears as part of the body of another loop
inner loop and outer loop - Answer: The nested loops are commonly referred to as the outer loop and inner loop.
developing programs incrementally - Answer: starting with a simple version of the program, and then growing the program little-by-little into a complete version
FIXME comment - Answer: attracts attention to code that needs to be fixed
break - Answer: causes an immediate exit of the loop
continue - Answer: causes an immediate jump to the while or for loop header statement
enumerate() - Answer: retrieves both the index and corresponding element values at the same time, providing a cleaner and more readable solution:
unpacking - Answer: a process that performs multiple assignments at once, binding comma-separated names on the left to the elements of a sequence on the right
open() - Answer: used to open a file from a directory. Gets input from a file
ex:
open()
closes - Answer: The () method closes the file, after which no more reads or writes to the file are allowed.
read() - Answer: method that returns the file contents as a string
readlines() - Answer: method returns a list of strings, where the first element is the contents of the first line, the second element is the contents of the second line, and so on
EOF - Answer: indicates no more data is available
"END OF FILE"
() - Answer: writes a string argument to a file
mode - Answer: indicates how a file is opened, e.g., whether or not writing to the file is allowed, if existing contents of the file are overwritten or appended, etc.
flush() - Answer: file method that can be called to force the interpreter to flush the output buffer to disk
function - Answer: a named series of statements
function call - Answer: Invokes a function's name
causes the function's statements to execute
def - Answer: creates a new function
function definition - Answer: consists of the def keyword, the new function's name, and a block of statements
block - Answer: a series of indented statements following the function definition
return - Answer: causes execution to jump back to where the original call occurred, returning execution to the next statement after the call.
parameter - Answer: influences a function's behavior via an input to the function
argument - Answer: An argument is an expression, such as 99, user_input, or user_input + 'Hi!'.
return statement - Answer: A function may return one output value using a ...
none - Answer: a special keyword that indicates no value
Hierarchical function calls and nested function calls - Answer: A function's statements may include function calls, known as hierarchical function calls or nested function calls. Code such as user_input = int(input()) consists of such a hierarchical function call, wherein the input() function is called and evaluates to a value that is then passed as an argument to the int() function.
polymorphism - Answer: The behavior of the function depends on the argument types
an inherent part of the Python language. For example, consider the multiplication operator *. If the two operands are numbers, then the result is the product of those two numbers. If one operand is a string and the other an integer, e.g., 'x' * 5 then the result is a repetition of the string 5 times: 'xxxxx'.
dynamic typing - Answer: determines the type of objects as a program executes
static typing - Answer: requires the programmer to define the type of every variable and every function parameter in a program's source code
incremental development - Answer: a small amount of code is written and tested, then a small amount more (an incremental amount) is written and tested, and so on.
function stubs - Answer: which are function definitions whose statements haven't been written yet
pass - Answer: performs no operation except to act as a placeholder for a required statement
NotImplementedError - Answer: indicates that the function is not implemented and causes the program to stop execution
bytecode - Answer: represents the statements to be executed by the function
slice notation - Answer: Multiple consecutive characters are read by using "this"
stride - Answer: determines how much to increment the index after reading each element. For example, mystr[0:10:2]
conversion specifier - Answer: a placeholder for a value in a string literal. For example, the expression 'age is %d' % (user_age) uses the %d conversion specifier as a placeholder for the value of user_age
conversion operator - Answer: inserts values from the tuple on the right into conversion specifiers on the left
conversion type - Answer: indicates how to convert the value to a string
minimum field width - Answer: placed immediately before the conversion type. It describes the minimum number of characters to be inserted in a string
conversion flags - Answer: alter the output of conversion specifiers
mapping key - Answer: specified by indicating the key of the relevant value in the dict within parenthesis
replace(old, new) - Answer: Returns a copy of the string with all occurrences of the substring old replaced by the string new. The old and new arguments may be string variables or string literals.
replace(old, new, count) - Answer: Same as above, except only replaces the first count occurrences of old.
find(x) - Answer: Returns the position of the first occurrence of item x in the string, else returns -1
find(x, start) - Answer: Same as find(x) but begins the search at position start
find(x, start, end) - Answer: Same find(x, start) but stops the search at position end
rfind(x) - Answer: Same as find but searches the string in reverse, returning the last occurrence in the string
count(x) - Answer: Returns the number of times x occurs in the string
isalnum() - Answer: Returns True if all characters in the string are lowercase or uppercase letters, or the numbers 0-9
isdigit() - Answer: Returns True if all characters are the numbers 0-9
islower() - Answer: Returns True if all characters are lowercase letters
isupper() - Answer: Return True if all characters are uppercase letters
isspace() - Answer: Return True if all characters are whitespace
startswith(x) - Answer: Return True if the string starts with x
endswith(x) - Answer: Return True if the string ends with x
capitalize() - Answer: returns a copy of the string with first character capitalized and the rest lowercased
lower() - Answer: Returns a copy of the string with all characters lowercased
upper() - Answer: Returns a copy of the string with all characters uppercased
strip() - Answer: Returns a copy of the string with leading and trailing whitespace removed
title() - Answer: Returns a copy of the string as a title, with first letters of words capitalized
split() - Answer: used to split up a string into a list of tokens
token - Answer: a sequence of characters that forms a part of a larger string
separator - Answer: a character or sequence of characters that indicates where to split the string into tokens
join() - Answer: method performs the inverse operation of split() by joining a list of strings together to create a single string
Content preview
zybook chapters 1-8 python Questions
and Complete Solutions Graded A+
computer program - Answer: Consists of instructions that a computer executes (or runs), like multiplying
numbers or printing a number to a screen.
task decomposition - Answer: Means to reduce a complex task into simpler basic steps, making the
whole task easier to solve.
algorithm - Answer: A recipe or a methodical step-by-step procedure to perform a task.
computational thinking - Answer: Evaluating a problem's most basic parts and then creating an
algorithm to solve that problem is commonly known as
Python interpreter - Answer: An application that can be used on various operating systems, including
Microsoft Windows, Linux, and MacOS.
interactive interpreter - Answer: A program that allows the user to execute one line of code at a time.
code - Answer: A common word for the textual representation of a program
line - Answer: A row of text
prompt - Answer: Indicates the interpreter is ready to accept code ">>>"
statement - Answer: A program instruction
expression - Answer: code that returns a value when evaluated;
variables - Answer: Named references to values stored by the interpreter.
,assignment - Answer: Creates a new variable by using the = value
comments - Answer: used to explain portions of code to a human reader. "# PA1"
print() - Answer: displays variables or expression values
string literal - Answer: Text enclosed in quotes is known as this. ('hello world')
new line character - Answer: A new line can also be output by inserting \n.
ex: "1/n2/n3"
input - Answer: Reads text entered by the user, and assigns the entered text to a variable. Causes the
interpreter to wait until the user has entered some text and has pushed the return key.
string - Answer: Always surrounded by single or double quotes, for example 'Hello' or "#Goodbye#
Amigo!".
type - Answer: Determines how a value can behave
int() - Answer: used to convert that string to the integer
syntax error - Answer: Violates a programming language's rules on how symbols can be combined to
create a program.
runtime error - Answer: a program's syntax is correct but the program attempts an impossible
operation, such as dividing by zero or multiplying strings together
crash - Answer: Abrupt and unintended termination of a program
, logic error - Answer: A logically flawed program. It works but the output is not correct for the given goal
for the program.
bug - Answer: another name for a logic error
integrated development environment - Answer: Code development. A way to create programs and test
them all in one.
bit - Answer: 0s and 1s (another way to call "binary numbers")
processor - Answer: created to process (aka execute) a list of desired calculations
instruction - Answer: each calculation output from processors
memory - Answer: circuits that can store 0s and 1s in each of a series of thousands of addressed
locations
program, application, or "app" - Answer: The programmer -created sequence of instructions
machine instructions - Answer: Instructions represented as 0s and 1s
executable program - Answer: a sequence of machine instructions
assembly - Answer: created programs called assemblers to automatically translate human readable
instructions
high-level languages - Answer: programmers created this to support programming using formulas or
algorithms, so a programmer could write complex formulas