Untitled Quiz
23 Questions
0 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

Which of the following statements about Python lists is true?

  • Lists cannot be changed once created.
  • Lists take up less space than tuples.
  • Lists allow for duplicate members. (correct)
  • Lists are unordered collections of items.
  • In Python, lists are the only way to store multiple values.

    False

    What is one advantage of using lists in Python according to the content?

    They allow for easier program development and maintenance.

    In Python, the index of the first element in a list is ______.

    <p>0</p> Signup and view all the answers

    What happens to the original values in a list after modifying an element?

    <p>The original value remains in the list unless explicitly overwritten.</p> Signup and view all the answers

    Which term also refers to a list in some programming languages?

    <p>Array</p> Signup and view all the answers

    Lists in Python can only contain elements of the same data type.

    <p>False</p> Signup and view all the answers

    Match the following list operations with their descriptions:

    <p>Append = Add an item to the end of the list Insert = Add an item at a specific index Remove = Delete an item from the list Access = Retrieve an item using its index</p> Signup and view all the answers

    What is the correct syntax for initializing a list in Python?

    <p>listName = [item1, item2, item3]</p> Signup and view all the answers

    In Python, the first element of a list has an index of 1.

    <p>False</p> Signup and view all the answers

    If a list named 'scores' is defined as scores = [10, 20, 30], what would scores[1] return?

    <p>20</p> Signup and view all the answers

    An attempt to access an index that does not exist in a list will result in an ______ error.

    <p>IndexError</p> Signup and view all the answers

    Match the following list indexing examples with the corresponding output:

    <p>print(grades[0]) = first grade print(grades[4]) = last grade print(foods[2]) = IndexError print(foods[1]) = bread</p> Signup and view all the answers

    What will happen if 'print(grades[3])' is executed given grades = [82, 73, 95, 100, 87]?

    <p>It will print 100.</p> Signup and view all the answers

    The command print(foods) will print 'kale' if the list is defined as foods = ['bananas', 'bread', 'kale'].

    <p>False</p> Signup and view all the answers

    What is the index of the last element in a Python list with 5 items?

    <p>4</p> Signup and view all the answers

    What will be the output of the following code if the list is [1, 2, 3, 4, 5]? for x in list: if x%2 == 0: print('Even') else: print('Odd')

    <p>Odd, Even, Odd, Even, Odd</p> Signup and view all the answers

    The variable failCount is initialized inside the loop.

    <p>False</p> Signup and view all the answers

    How many grades in the list [97, 89, 52, 70, 91, 64] are considered failing?

    <p>1</p> Signup and view all the answers

    In the list [1, 2, 3, 4, 5], the value at index 3 is ______.

    <p>4</p> Signup and view all the answers

    When using the list grades = [97, 89, 52, 70, 91, 64], what is the index for the grade of 91?

    <p>5</p> Signup and view all the answers

    The statement 'if x < 70:' checks for grades that are passing.

    <p>False</p> Signup and view all the answers

    What happens to the variable failCount each time a grade less than 70 is encountered?

    <p>It increments by 1</p> Signup and view all the answers

    Study Notes

    Summary of Progressive Science Initiative (PSI)

    • PSI is a progressive science initiative.
    • Materials are freely available at www.njctl.org for non-commercial use by students and teachers.
    • Commercial use is prohibited without written permission from NJCTL.
    • The New Jersey Education Association (NJEA) supports NJCTL, an independent non-profit organization.
    • NJCTL's mission is to empower teachers to enhance school improvement for student benefit.

    AP Computer Science Principles - Lists

    • Lists are used to store multiple values, simplifying programming.
    • They are ordered, changeable, and allow duplicate members
    • This course focuses on lists. Transversing & Searching Lists, Adding to Lists, More with Lists, and Strings are Lists! are covered in different sections.
    • Lists are indexed starting at 0 (the first element)
    • Pseudocode and Python lists are similar in concept but use different syntax (e.g., brackets vs. just the name). Be careful about how different programming languages index lists
    • Positive and negative indexing: Positive indexing counts from the beginning of a list, negative from the end
    • Use of lists is shown with Python and AP Pseudocode examples.

    Python Collections

    • Storing multiple values efficiently in programming.
    • Creating 15 different variables for grades is impractical.
    • Creating variables for every student is also impractical
    • Python Collections includes Lists, Tuples, Sets and Dictionaries.
    • Lists offer an organized, simple way to store multiple values.
    • The practical examples provided in the materials demonstrate how lists improve grade keeping for multiple assignments and students

    Data Abstraction with Lists

    • Data abstraction separates the abstract properties and concrete details in a data type.
    • It keeps programs manageable and simple. This includes lists as collections of values, instead of many individual variables
    • Lists can aggregate values into one entry, simplifying code management
    • Elements of lists can consist of different data types within a single list.

    Lists Indexes

    • Lists elements are accessed using their index (position).
    • The first element has index 0.
    • Attempting to access with an index beyond the list range results in an error. Always remember elements are listed 0,1,2 etc, not 1,2,3 etc for python programming. Pseudocode uses a different start index (e.g. 1 instead of 0).

    AP Pseudocode Lists

    • On the AP Exam, pseudocode for lists can have different forms of expressions (text or block-based).
    • Using arrows that are used to show the storage of contents (Pseudocode).
    • The notation for lists can look similar to Python lists (e.g., using brackees [] in Python, similar notations in pseudocode, but not always the same).

    AP Pseudocode List Indexes

    • Pseudocode lists use indexes starting at 1 and not 0
    • Trying to access an element at an invalid index results in an error.

    AP Pseudocode Empty List

    • Creating an empty list using pseudocode.
    • Creating a copy of a list, in pseudocode.

    AP Pseudocode Lists and Variables

    • Assigning values to, and retrieving values from, list elements using pseudocode notation
    • Pseudocode for copying an entire list, instead of copying manually.

    Lists in Practical Programming

    • Demonstrations using Python.

    Negative Indexes

    • Accessing elements from the end of a list (-1 is last, -2 next to last etc.)
    • Negative index use in Python
    • Negative indexing cannot be used in AP Pseudocode.

    Range of Indexes

    • Accessing segments of a list, using colon to select desired index ranges.
    • Short-hand notation using colon for selecting elements without explicitly stating the initial index if it is the beginning of the list
    • Selecting elements from a specific index until the end of the list using colon syntax.

    Live Code It

    • Using loops and lists to create lists and print out information.
    • Examples using loops to create lists
    • Practical examples to demonstrate using loops to process list items

    Searching Lists in Python

    • Checking for elements in lists using if statements.
    • Algorithms for searching within lists (linear and binary) are explained.

    Searching Algorithms

    • Descriptions of linear and binary search algorithms
    • Examples for these searches using lists are presented
    • Understanding when each method might be best is necessary.

    Output Questions

    • Answers to code segments are shown.

    Adding to Lists

    • Adding elements to the end of a list, using append in Python.
    • Demonstrations of creating lists in empty lists

    Adding Elements in Lists

    • How to add elements to a list (using append() method in Python
    • Adding elements to an empty list
    • Adding to specified indexes (using insert() method in Python).

    Adding Elements Using Loops

    • Examples of adding elements to a list based on indexes in the list (by position in order), by specified indexes, using loops (for and while)

    AP Pseudocode Adding Elements in Lists

    • Adding elements using APPEND() in AP Pseudocode
    • Demonstrates examples using the APPEND() method in pseudocode.

    Removing Elements from Lists

    • How to remove elements, using remove() in Python lists
    • Removing elements using pop() method, from specified indexes

    Removing Items from Lists

    • Removing elements using pop() and del in Python

    Additional String Methods

    • Using upper and lower to change cases of each letter in strings.
    • Description on the split method on string for splitting data into a list in Python

    Strings are Lists!

    • Explanation on each character of a string having index values.
    • Accessing characters in a string
    • Accessing specific characters in a string, either by one specific index or a range of indexes
    • Demonstrating how to determine the length of a string, using the len() method.

    More Useful String Methods (Includes Useful Methods for Strings)

    • Converting strings to upper or lower case
    • Splitting strings into lists using the split() method

    AP Pseudocode FOR EACH Loops

    • Explanation and examples of for each loops in pseudocode.
    • Demonstration of how for each loops work through particular elements in lists

    Additional Discussion Points on Lists

    • Practical examples for using and modifying Python lists
    • Demonstrating the role of indexes, and loops to efficiently process list items, add items, or remove items.

    Studying That Suits You

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

    Quiz Team

    Related Documents

    More Like This

    Untitled Quiz
    6 questions

    Untitled Quiz

    AdoredHealing avatar
    AdoredHealing
    Untitled Quiz
    19 questions

    Untitled Quiz

    TalentedFantasy1640 avatar
    TalentedFantasy1640
    Untitled Quiz
    18 questions

    Untitled Quiz

    RighteousIguana avatar
    RighteousIguana
    Untitled Quiz
    50 questions

    Untitled Quiz

    JoyousSulfur avatar
    JoyousSulfur
    Use Quizgecko on...
    Browser
    Browser