Starting Out With Python Chapter 2 Flashcards
83 Questions
101 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What are the five phases of creating a program that works correctly?

  1. Design the program, 2. Write the code, 3. Correct Syntax errors, 4. Test the program, 5. Correct logic errors.

What is a logic error?

An error in a program that makes it do something other than what the programmer intended. It does not prevent the program from running, but causes it to produce incorrect results.

What is debugging?

Finding and fixing problems in your algorithm or program.

Define an algorithm.

<p>A set of well-defined logical steps that must be taken to perform a task.</p> Signup and view all the answers

What is pseudocode?

<p>Shorthand notation for programming which uses a combination of informal programming structures and verbal descriptions of code.</p> Signup and view all the answers

What are flowcharts used for?

<p>A graphical representation of the steps in a process; details all of the elements in a process and the sequence in which these elements occur.</p> Signup and view all the answers

What are terminal symbols in flowcharts?

<p>The ovals that appear at the top and bottom of the flowchart, marking the start and end points.</p> Signup and view all the answers

What does an input symbol indicate in a flowchart?

<p>It indicates an input operation and is represented by a parallelogram.</p> Signup and view all the answers

What does an output symbol indicate in a flowchart?

<p>It indicates an output operation and is represented by a parallelogram.</p> Signup and view all the answers

What do processing symbols represent in a flowchart?

<p>They represent steps in which the program performs some process on data, such as a mathematical calculation.</p> Signup and view all the answers

Who is a programmer's customer?

<p>Any person, group, or organization that is asking you to write a program.</p> Signup and view all the answers

What is a software requirement?

<p>A single task that the program must perform in order to satisfy the customer.</p> Signup and view all the answers

In Python, string literals must be enclosed in ________________________.

<p>single or double quotation marks.</p> Signup and view all the answers

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

<p>double-quote marks.</p> Signup and view all the answers

Python also allows you to enclose string literals in ________ ___________ when they contain both single and double quotes.

<p>triple quotes.</p> Signup and view all the answers

What are comments in programming?

<p>Short notes placed in different parts of a program, explaining how those parts of the program work.</p> Signup and view all the answers

What character is used to begin a comment in Python?

<h1>character.</h1> Signup and view all the answers

What is a variable?

<p>A name that represents a value stored in the computer's memory.</p> Signup and view all the answers

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

<p>references the value.</p> Signup and view all the answers

You use an ______________________ __________________ to create a variable and make it reference a piece of data.

<p>assignment statement.</p> Signup and view all the answers

An assignment statement is written in this general format: ______

<p>variable = expression.</p> Signup and view all the answers

The = sign is known as the ______________ _______________.

<p>assignment operator.</p> Signup and view all the answers

When you pass a variable as an argument to the print function, you do NOT enclose the variable name in ___________ _____________.

<p>quotation marks.</p> Signup and view all the answers

In an assignment statement, the variable that is receiving the assignment must appear on the ____________ side of the = operator.

<p>left.</p> Signup and view all the answers

You cannot use a variable until you have __________ a value to it.

<p>assigned.</p> Signup and view all the answers

What are the variable naming rules?

<ol> <li>You cannot use Python's keywords. 2. It cannot contain spaces. 3. The first character must be a letter or an underscore. 4. The remaining characters may include letters, digits, or underscores. 5. Uppercase and lowercase characters are distinct.</li> </ol> Signup and view all the answers

What is garbage collection?

<p>Releases memory that was used for a variable's value once the variable is no longer in use.</p> Signup and view all the answers

What is variable reassignment?

<p>To change the value of a variable based on its current value.</p> Signup and view all the answers

Python uses __________ to categorize values in memory.

<p>data types.</p> Signup and view all the answers

What classification does an integer fall under in Python?

<p>int.</p> Signup and view all the answers

What classification does a real number fall under in Python?

<p>float.</p> Signup and view all the answers

How does Python classify a number written directly in code?

<p>numeric literal.</p> Signup and view all the answers

You cannot write __________, __________, __________ in numeric literals.

<p>currency symbols, spaces, or commas.</p> Signup and view all the answers

What does the 'str' data type represent in Python?

<p>A Python data type that holds a string of characters.</p> Signup and view all the answers

In Python, a __________ is just a name that refers to a piece of data.

<p>variable.</p> Signup and view all the answers

When a program reads data from the keyboard, usually it stores that data in a ____________.

<p>variable.</p> Signup and view all the answers

What are nested function calls?

<p>Where one function calls another.</p> Signup and view all the answers

In a print statement, you can set the _____ argument to a space or empty string to stop the output from advancing to a new line.

<p>end.</p> Signup and view all the answers

Which of the following statements about algorithms is NOT true?

<p>An algorithm allows ambiguity.</p> Signup and view all the answers

During testing, what errors can runtime testing expose?

<p>Logic errors.</p> Signup and view all the answers

What is a string constant?

<p>A specific group of characters enclosed within quotation marks.</p> Signup and view all the answers

What is an empty string?

<p>A string value that has no characters, represented in code as '' or &quot;&quot;.</p> Signup and view all the answers

If a variable is associated with the value 'red', what would the code look like?

<p>foreground = 'red'.</p> Signup and view all the answers

What is method invocation?

<p>The line of code that causes a method to be executed.</p> Signup and view all the answers

What expression can you use to calculate the amount of change from an integer price in cents?

<p>price % 100.</p> Signup and view all the answers

What expression can you use to find the last digit of an integer?

<p>x % 10.</p> Signup and view all the answers

The character escape sequence to force the cursor to go to the next line is __________.

<p>n.</p> Signup and view all the answers

What does it mean that variables can reference different values?

<p>They can be assigned new values during program execution.</p> Signup and view all the answers

A numeric literal that is written as a _____________ ______________ with no decimal point is considered an int.

<p>whole number.</p> Signup and view all the answers

A numeric literal that is written as a ______________ _____________ is considered a float.

<p>decimal point.</p> Signup and view all the answers

What function reads data from the keyboard?

<p>input function.</p> Signup and view all the answers

In the general format, _____________ is a string that is displayed on the screen.

<p>prompt.</p> Signup and view all the answers

What is an exception in programming?

<p>An unexpected error that occurs while a program is running.</p> Signup and view all the answers

What are math operators?

<p>A programmer's tools for performing calculations.</p> Signup and view all the answers

What does the '+' operator do in Python?

<p>Adds two numbers.</p> Signup and view all the answers

What does the '-' operator do in Python?

<p>Subtracts one number from another.</p> Signup and view all the answers

What does the '*' operator do in Python?

<p>Multiplies one number by another.</p> Signup and view all the answers

What does the '/' operator do in Python?

<p>Divides one number by another and gives the result as a floating-point number.</p> Signup and view all the answers

What does the '//' operator do in Python?

<p>Divides one number by another and gives the result as a whole number.</p> Signup and view all the answers

What does the '%' operator do in Python?

<p>Divides one number by another and gives the remainder.</p> Signup and view all the answers

What does the '**' operator do in Python?

<p>Raises a number to a power.</p> Signup and view all the answers

What are operands?

<p>Values that the + operator adds together.</p> Signup and view all the answers

What is a mixed-type expression?

<p>An expression that contains operands of different data types.</p> Signup and view all the answers

What is the line continuation character in Python?

<p>Backslash ().</p> Signup and view all the answers

Python allows you to break any part of a statement that is enclosed in ________________ without using the line continuation character.

<p>parentheses.</p> Signup and view all the answers

What is a newline character?

<p>A special command that causes the computer to start a new line of output.</p> Signup and view all the answers

What does 'end=' ' mean in the print function?

<p>It causes the function to NOT add a newline at the end of the string.</p> Signup and view all the answers

What does 'end=''' mean in the print function?

<p>It causes the function to NOT add a newline at the end of the string and NOT add a space.</p> Signup and view all the answers

What does 'sep=''' do when passing multiple arguments to the print function?

<p>Specifies what should separate the items being printed.</p> Signup and view all the answers

What is an escape character in Python?

<p>A special character that is preceded with a backslash ().</p> Signup and view all the answers

What does ' ' represent in Python?

<p>The newline escape character.</p> Signup and view all the answers

What does ' ' do in Python?

<p>Advances the output to the next horizontal tab position.</p> Signup and view all the answers

What does ''' allow you to do in Python?

<p>Causes a single quotation mark to be printed.</p> Signup and view all the answers

What does ''' allow you to do in Python?

<p>Causes a double quotation mark to be printed.</p> Signup and view all the answers

What does '\' do in Python?

<p>Causes a backslash character to be printed.</p> Signup and view all the answers

What does string concatenation mean?

<p>Appending one string to another using the + operator.</p> Signup and view all the answers

What does the format function do in Python?

<p>It formats numeric values based on specified format specifiers.</p> Signup and view all the answers

What is a format specifier?

<p>A string that contains special characters specifying how the numeric value should be formatted.</p> Signup and view all the answers

What does '.2f' as a format specifier do?

<p>Prints the number with 2 decimal places.</p> Signup and view all the answers

What does 'e' mean in scientific notation format in Python?

<p>Display floating-point numbers in scientific notation.</p> Signup and view all the answers

What does the minimum field width specify when formatting numbers?

<p>The minimum number of spaces allowed to display the value.</p> Signup and view all the answers

How do you format integers using the format function?

<p>Use 'd' as the type designator.</p> Signup and view all the answers

What is a magic number?

<p>An unexplained value that appears in the program's code.</p> Signup and view all the answers

Study Notes

Programming Process

  • Creating a program involves five phases: design, write code, correct syntax errors, test, and correct logic errors.

Error Types

  • Logic Error: A mistake that leads to unintended behavior without stopping the program, often due to mathematical errors.
  • Debugging: The process of finding and fixing errors in an algorithm or program.

Algorithm and Programming Concepts

  • Algorithm: A structured sequence of logical steps for performing a task.
  • Pseudocode: A readable mix of informal programming structures and natural language used to outline algorithms.

Flowcharts

  • Flowcharts: Visual diagrams representing the steps in a process; they detail the elements and their sequences.
  • Terminal Symbols: Ovals in flowcharts denote the program’s starting and ending points.
  • Input/Output Symbols: Parallelograms in flowcharts indicate input and output operations.

Programming Elements

  • Variables: Named locations in memory for storing data; they can change values based on assignment.
  • Assignment Statement: Syntax to create a variable and reference data; follows the format: variable = expression.
  • Garbage Collection: Mechanism that releases memory from variables no longer in use.

Data Types

  • Numeric Types: int for integers and float for real numbers; numeric literals cannot include currency symbols, spaces, or commas.
  • Strings: Sequences of characters stored as data, enclosed in single or double quotation marks, or triple quotes for mixed content.

Comments

  • Comments: Notes in code for explanation, ignored by the interpreter; begin with # and can be end-line comments or multi-line.

Functions

  • Function: Pre-written code that performs specific operations; executed by calling the function with appropriate arguments.

Input and Output

  • Input Function: Reads data from the keyboard and returns it as a string.
  • Print Function: Displays output; parameters like end and sep control formatting.

Escape Characters

  • Escape Characters: Special characters for achieving specific formatting in strings, such as:
    • \n: Newline
    • \t: Horizontal tab
    • \\: Backslash

String Operations

  • String Concatenation: Joining strings using the + operator.

Formatting Output

  • Format Function: Handles numeric formatting with specifiers; including '.2f' for two decimal places.
  • Named Constants: Values that cannot be altered during program execution, helpful for managing fixed values.

Mixed-Type Expressions

  • Expressions with operands of different data types are termed mixed-type expressions.

Special Considerations

  • Variable Naming Rules: Variables must not include keywords, spaces, must start with a letter or underscore, and are case-sensitive.
  • Handling Unexpected Errors: Exceptions occur when unhandled errors happen during program execution.

Miscellaneous

  • Logic Testing: Ensuring the program performs as expected under various conditions to expose runtime errors.

Magic Numbers

  • Magic Number: Unexplained numerical values in code; should be avoided for clarity.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Description

This quiz covers key concepts from Chapter 2 of 'Starting Out With Python'. Focused on program development phases and error types, it serves as a valuable study aid for understanding fundamental programming principles. Test your knowledge and reinforce your learning with these flashcards.

More Like This

Use Quizgecko on...
Browser
Browser