AP Computer Science Principles Lists PDF
Document Details
Uploaded by CrispLeibniz
null
2021
null
null
Tags
Summary
This document covers lists in computer science programming, particularly introductory concepts of Python. It includes examples of Lists, Data Abstraction, and different list methods used in Python programming. The document does not contain questions and answers, therefore is not a past paper (exam).
Full Transcript
AP Computer Science Principles Lists 2021-03-23 www.njctl.org Table of Contents Click on a topic to go to that section Lists Traversing & Searching Lists Adding to Lists More with Lists Strings are Lists! ...
AP Computer Science Principles Lists 2021-03-23 www.njctl.org Table of Contents Click on a topic to go to that section Lists Traversing & Searching Lists Adding to Lists More with Lists Strings are Lists! Lists Return to Table https://njctl.org/video/?v=_ZKKSaUCNpA of Contents Python Collections There are times in programming where we must store many values, not just one or two. In these cases, it is not practical to assign a variable/identifier to every value. For example, let's say we want to write a program that will store a student's grades for the marking period. There are 15 assignments. Would you declare 15 different variables? Furthermore, if you had a total of 80 students, would you declare variables for each of them? score1 = 80 score2 = 75 score3 = 87 score4 = 92 //etc... Python Collections We can see how it is extremely impractical to declare such a vast amount of variables and be able to keep track of them! More importantly, even if we did, what would happen the next marking period? Would you create 15 new variables? Would you delete all the values stored in the first 15 variables? Python Collections Python has 4 ways of gathering data types into a collection: Lists, Tuples, Sets and Dictionaries. In this course, we will only be focusing on Lists. However, you can quickly Google the others to see how to use them if the need arises for you. List: a collection which is ordered, changeable, and allows for duplicate members. Data Abstraction with Lists Data abstraction provides a separation between the abstract properties of a data type and the concrete details of its representation. Data abstractions manage complexity in programs by giving a collection of data a name without referencing the specific details of the representation. Data abstractions can be created using lists. Instead of creating endless variables each containing data, all of the values can be treated like one value. This will result in a program that is easier to develop and maintain. Sometimes a list is called an "array" in other programming languages, and lists often contain different types of elements. Let's see how a list can improve our grades program... Lists A List can help us in this "grades" scenario because it can hold and work with a list of values. Lists work similarly to a spreadsheet using rows and columns that store data in each box/compartment. Here is a visual of our grades list. Below we have included 7 scores, but it can get as long as you want. Notice how the position (or index) of the first grade actually begins at 0. 80 75 87 92 67 74 90 test score #1 test score #5 index: 0 index: 4 Lists Here is the Python syntax for initializing a list: This is the name you assign to your list listName = [item1, item2, item3] Separate each Use [ ] to hold the element with a ",". elements (contents) of Remember that string your list. elements go in " ". Each element in a list can be accessed by its index (position in the list). The first element has an index of 0. Lists Indexes For our grades program, we can start by initializing a variable to hold a series of grades, like this: grades = [82, 73, 95, 100, 87] We can work with each individual grade by using this notation: grades[index] Therefore... grades = 82 Don't forget that index values grades = 73 begin with 0 and not 1 in grades = 95 Python! The first item in the list grades = 100 has an index value of zero. grades = 87 Lists Indexes grades = [82, 73, 95, 100, 87] For example, if you want to print out the first grade in the list, you would write the command: print(grades) This will print out "82". Lists Indexes foods = ["bananas","bread","kale"] Here is an example of a list that contains strings. As you can see, each food item is wrapped in quotation marks. The command: print(foods) will print out "kale". However! If you were to run this command: print(foods) you would get an error. It would say "IndexError: list index out of range" because there is no item in the list with an index value of 3. AP Pseudocode Lists On the AP exam, you may see either of the following expressions of a list created in AP Pseudocode, depending on whether the problem is using text-based or block-based code. listName [item1, item2, item3] It looks very similar to the Python statements with the exception of the arrow used to show storage of content. AP Pseudocode List Indexes Lists written in AP Pseudocode also use index values to access specific elements in the list. Accessing elements in an AP Pseudocode list looks much the same as gathering elements from a Python list. The biggest difference with AP Pseudocode lists is that the first index value is 1 NOT 0. #Index Value: 1 2 3 4 5 grades [82, 73, 95, 100, 87] DISPLAY(grades) #This will output 82 #This will output 73 AP Pseudocode Empty List list1 [] The above code creates an empty list. list2 list1 The above code assigns a copy of list1 to list2. For example... list1 [1,2,3] list2 list1 // list2 now holds [1,2,3] as well AP Pseudocode Lists and Variables list1[i] x The above code assigns the value of x to list1[i]. x list1[i] The above code assigns the value of list1[i] to the variable x. list1[i] list1[j] The above code assigns the value of list1[j] to list1[i]. 1 Given the code segment below, what will print out? grades = [82, 73, 95, 100, 87] print(grades) A 73 B 95 Answer C 100 D 87 E I need help https://njctl.org/video/?v=ItjEjw-f8As 2 Given the code segment below, what will print out? ages [14, 13, 25, 30, 27] DISPLAY(ages) DISPLAY(ages) Answer A 14 30 B 13 27 C 13 27 D 14 30 https://njctl.org/video/?v=fnQgeaEIRhA E I need help 3 Given the code segment below, what will print out? food = ["milk", "cheese", "eggs"] print(food) A milk B cheese Answer C eggs D An error occurs E I need help https://njctl.org/video/?v=2gtwoQWrqtQ 4 Given the code segment below, what will print out? food = ["milk", "cheese", "eggs"] print(food) A milk B cheese Answer C eggs D An error occurs E I need help https://njctl.org/video/?v=pXV15o9vaGg Negative Indexes We can also reference items from the end of the list. Look at our grades list again. If we want to print out the last grade, but do not know how many grades there are, we can use negative indexes to start at the end of our list. So, the following segment will print out 87: grades = [82, 73, 95, 100, 87] print(grades[-1]) It is important to note that while the first element in the list starts at index 0, when beginning with the last element in the list, the index starts at -1. The code segment below will print out 100: #Negative Index: -5 -4 -3 -2 -1 grades = [82, 73, 95, 100, 87] print(grades[-2]) https://njctl.org/video/?v=2XbaS9IrGu8 OUTPUT: 100 AP Pseudocode Negative Indexes AP Pseudocode does NOT use negative indexes. On the AP test, if a list index is less than 1, or greater than the length of the list, there will be an error and the program will end. grades [82, 73, 95, 100, 87] X DISPLAY(grades[-2]) ERROR! grades [82, 73, 95, 100, 87] X DISPLAY(grades) ERROR! 5 Given the code segment below, what will print out? grades = [82, 73, 95, 100, 87] print(grades[-3]) A 73 B 95 Answer C 100 D 87 E I need help https://njctl.org/video/?v=X-TGxeD692Y 6 Given the code segment below, what will print out? food = ["milk", "cheese", "eggs"] print(food[-1]) A milk B cheese Answer C eggs D An Error Occurs E I need help https://njctl.org/video/?v=j8JnD64PIf0 7 Given the code segment below, what will print out? grades = [82, 73, 95, 100, 87] print(grades[-6]) A 73 B 95 Answer C 100 D An Error Occurs E I need help https://njctl.org/video/?v=M4zkmXnEQoU 8 Given the code segment below, what will print out? grades [82, 73, 95, 100, 87] DISPLAY(grades[-3]) A 73 Answer B 95 C 100 D An Error Occurs E I need help https://njctl.org/video/?v=YFxGuQH8Idw Range of Indexes We can also print out a range of numbers using indexes. For example, if we want to print out the first 3 grades in our list, we would use a ":" to separate the first and last (not included) desired indexes like this: grades = [82, 73, 95, 100, 87] print(grades[0:3]) The first grade is at index 0, the second at index 1, and the third at index 2. Since the last value in the range is not included, we want to go up to 3, in order to include the grade at index 2. https://njctl.org/video/?v=ES2u2x9xS5g Range of Indexes There are also some nifty short cuts in Python! 1) When you want the range to start at the beginning of the list, you don't even need to write 0. So the code from before: grades = [82, 73, 95, 100, 87] print(grades[0:3]) Can also be written like this: grades = [82, 73, 95, 100, 87] print(grades[:3]) Range of Indexes The same thing can be done going to the end of the list! Remember that in order to include the last index in the range, the second value must be one more than the last index value, which can get confusing. 2) When you want the range to start at a specific index but go to the end, you can short hand it and cut off the second value in the [ ]. So the code below which would print [95, 100, 87]: grades = [82, 73, 95, 100, 87] print(grades[2:5]) Can also be written like this: grades = [82, 73, 95, 100, 87] print(grades[2:]) 9 Given the code segment below, what will print out? grades = [82, 73, 95, 100, 87] print(grades[2:4]) A [73, 95] B [95, 100] Answer C [73, 95, 100] D [95, 100, 87] E I need help https://njctl.org/video/?v=j69iZ2E7PLY 10 Given the code segment below, what will print out? food = ["milk", "cheese", "eggs"] print(food[1:2]) A ['milk', 'cheese'] B ['cheese', 'eggs'] Answer C ['cheese'] D ['milk'] E I need help https://njctl.org/video/?v=FLP9zS7pnzY 11 Given the code segment below, what will print out? food = ["milk", "cheese", "eggs"] print(food[:2]) A ['milk', 'cheese'] B ['cheese', 'eggs'] Answer C ['cheese'] D ['milk'] E I need help https://njctl.org/video/?v=x7xdkiQSz1g 12 Given the code segment below, what will print out? grades = [82, 73, 95, 100, 87] print(grades[3:]) A [95, 100, 87] B [100, 87] Answer C [73, 95, 100] D An Error Occurs E I need help https://njctl.org/video/?v=EofVPTAGFCA IDE; Live codeIt! //LIVE Let's practice creating a list. Create a list that contains all of the names of the guests coming to a birthday party. The names are "Susan," "Maria," "Robert," "Kate," and "John." Below is a visual of what we want to create with what the index of each name in the list would be. Susan Maria Robert Kate John index: 0 1 2 3 4 https://njctl.org/video/?v=eQ6IgYEwP7o IDE; Live codeIt! //LIVE In Python, the code segment would look like this: list is named name of each guest in "guests" quotes guests = ["Susan","Maria","Robert","Kate","John"] separate each name with a comma IDE; Live codeIt! //LIVE Now let's access a name. Print out the name in the compartment with an index value of 2 ("Robert"). Susan Maria Robert Kate John index: 0 1 2 3 4 We can do this with the code below. guests = ["Susan","Maria","Robert","Kate","John"] print(guests) list name index we want to access Live codeIt! IDE; //LIVE We can also change the elements. For example, what if Maria is no longer attending the party, but our other friend Joe will be attending. We want to change "Maria" to "Joe" inside the compartment with an index value of 1 (the second name in the list). guests = ["Susan","Maria","Robert","Kate","John"] guests = "Joe" print(guests) This will now print out Joe. Let's practice modifying list items. 13 Given the code segment below, what will print out? food = ["milk", "cheese", "eggs"] food = "spinach" print(food) Answer A milk B cheese C eggs D spinach E I need help https://njctl.org/video/?v=90QpjKpZsvY 14 Given the code segment below, what will print out? food = ["milk", "cheese", "eggs"] food = "spinach" print(food) Answer A milk B cheese C eggs D spinach E I need help https://njctl.org/video/?v=i01c9yIjXrc 15 Given the code segment below, what will print out? food = ["milk", "cheese", "eggs"] food = "spinach" food = "peanut butter" print(food) Answer A peanut butter B cheese C eggs D spinach https://njctl.org/video/?v=2sB_wQAlfCk E I need help codeIt!Now Create a list named num storing the values 1, 3, 4, 5 and then another called iceCream storing three types of ice cream flavors. Print out a statement like the one given below by accessing values in your lists. We bought 4 strawberry ice creams. https://njctl.org/video/?v=8Biz7ELv7EE codeIt!Now Possible Solution num = [1, 3, 4, 5] iceCream = ["strawberry", "vanilla", "chocolate"] print("We bought " + str(num) + " " + iceCream + " ice creams.") Traversing & Searching Lists Return to Table of Contents https://njctl.org/video/?v=Jw49UAsPOow Using Loops with Lists What if we now want to print out our entire guest list? It would be difficult and tedious to write a print statement for each person. We could do this: guests = ["Susan","Maria","Robert","Kate","John"] print(guests) Most of the time, this would work just fine, however, you cannot format your output. It will always print like this: ['Susan','Maria','Robert','Kate','John'] What if we wanted each name to print out on its own line without the brackets? Using Loops with Lists This is where our for loops come in handy! As we learned in the previous unit, a for loop can traverse through a word letter by letter. It can do the same with each element in a list. Below is our guests list again: guests = ["Susan","Maria","Robert","Kate","John"] Keep in mind, in these examples, we will be traversing the entire list. However, it is also possible to only traverse part of a list, which is called a partial traversal. Using Loops with Lists If we want to print it out in its entirety one name at a time, we set up the for loop like this: guests = ["Susan","Maria","Robert","Kate","John"] x is the variable that will hold each element of the list, respectively. for x in guests: print(x) guests is the list name that we want to traverse (run through). print(x) will print each name in the list, one after the other. Using Loops with Lists This code segment: guests = ["Susan","Maria","Robert","Kate","John"] for x in guests: print(x) Will now output like this: Susan Maria Robert Kate John 16 Given the code segment below, what will print out? food = ["milk", "cheese", "eggs"] print(food) A ['milk','cheese','eggs'] Answer B milk cheese eggs C ['milk'] D milk, cheese, eggs E I need help https://njctl.org/video/?v=3yA62bQeuZk 17 Given the code segment below, what will print out? food = ["milk", "cheese", "eggs"] for x in food: print(x) Answer A ['milk','cheese','eggs'] B milk cheese eggs C ['milk'] D milk, cheese, eggs https://njctl.org/video/?v=R3g3V5S46w0 E I need help 18 Given the code segment below, what will print out? food = ["milk", "cheese", "eggs"] for x in food: print("hello") Answer A ['milk','cheese','eggs'] B milk C hello cheese hello eggs hello D hello, hello, hello E I need help https://njctl.org/video/?v=EXNyyVM-tlo Lists and Loops A loop (or several) can help us do many things, here are just a few: 1) Print the elements of a list (as we just saw). 2) Search the elements of a list. 3) Fill the elements of a list. 4) Change/Alter elements of a list. Let's take a look at each one separately. https://njctl.org/video/?v=EJ0xoK_MmDw Searching Lists in Python Python allows you to check for items in a list using if statements. Below is our guests list again. guests = ["Susan","Maria","Robert","Kate","John"] To check to see if "Kate" is invited to the party, we can write a code segment like this: The element to look for. if "Kate" in guests: print("Yes, Kate is invited") The list being checked. What to do when the "if" is TRUE. Searching Algorithms There are different kinds of search algorithms. Linear search or sequential search algorithms check each element of a list, in order, until the desired value is found or all elements in the list have been checked. The binary search algorithm starts at the middle of a sorted data set of numbers and eliminates half of the data; this process repeats until the desired value is found or all elements have been eliminated. An example of a binary search is finding a word in the dictionary. First, you start in the middle of the book. Does the word start with A through M or N through Z? If the word is "splendid", the computer will "throw away" A - M and search N - Z next. The computer keeps cutting the data in half until the word is found. This can be a much faster searching algorithm than a linear search if the amount of data is very large. However, data must be sorted and put in order for binary search to work. 19 What will the following code segment output? list = [2, 4, 6, 8] for x in list: if x%2 == 0: Answer print("Even") A Even C Odd else: B Even D Odd print("Odd") Even Odd Even Odd Even Odd E I Need Help https://njctl.org/video/?v=lGjwED21yeA 20 What will the following code segment output? list = ["hi", "there"] if "hi" in list: A True C False Answer print("True") else: B Error D True False print("False") E I Need Help https://njctl.org/video/?v=G6MJ25g0BsE 21 What will the following code segment output? list = [1, 2, 3, 4, 5] for x in list: if x%2 == 0: A Even C Odd print("Even") Even Odd Answer else: Even print("Odd") Odd B Even D Odd Even Odd Even Odd Even Odd E I Need Help https://njctl.org/video/?v=SNjhRz6drOY Live codeIt! IDE; //LIVE What if we had a list that held the grades of a student and we wanted to check if the student failed any assignments? grades = [97, 89, 52, 70, 91, 64] Consider anything below a 70% to be failing. 97 89 52 70 91 64 https://njctl.org/video/?v=3LryAJZz9hM IDE; Live codeIt! //LIVE Each value is stored at a different index in the list, therefore, it has a location that can be referenced (i.e. we know that at grades we will find the value of 70). grades = [97, 89, 52, 70, 91, 64] failCount = 0 for x in grades: if x < 70: failCount+=1 print ("You failed " + str(failCount) + " grades.") Let's go through this line by line... Live codeIt! IDE; //LIVE grades = [97, 89, 52, 70, 91, 64] ## fills in grades list with the values failCount = 0 ## initializes a variable to count the # of failing ## grades. You need to declare this variable before ## the loop, so that it is not reset to 0 each time ## the loop runs, and so that you can still access ## the variable after the loop is over. IDE; Live codeIt! //LIVE grades = [97, 89, 52, 70, 91, 64] failCount = 0 for x in grades: ## this loop accesses each grade in the list if x < 70: failCount+=1 ## if the grade in that compartment is less ## than 70, it will increment failCount by 1. print ("You failed " + str(failCount) + "grades.") ## after the loop is over, we print the final value of failCount which represents the total failed grades IDE; Live codeIt! //LIVE grades = [97, 89, 52, 70, 91, 64] failCount = 0 for x in grades: if x < 70: failCount+=1 print ("You failed " + str(failCount) + " grades.") You failed 2 grades. IDE; Live codeIt! //LIVE What if the teacher decided that everyone deserved 10 bonus points on every assignment except the 4th assignment? So the grades would go from this: 97 89 52 70 91 64 To this: 107 99 62 70 101 74 IDE; Live codeIt! //LIVE What if the teacher decided that everyone deserved 10 bonus points on every assignment except the 4th assignment? grades = [97, 89, 52, 70, 91, 64] i = 0 while i < 6: if i != 3: grades[i] += 10 i+=1 107 99 62 70 101 74 22 What is the output of the following code? names = [ ] if "Mary" in names: print (names) Answer A ['Mary', 'Mary'] C Nothing outputs B ['Mary'] D Runtime Error E I need help https://njctl.org/video/?v=UD-ADyusHtQ 23 What is the output of the following code? names = ["John", "Mary", "Mary"] if "John" in names: print( "true" ) Answer A ['John', 'Mary', 'Mary'] C Nothing outputs B true D Runtime Error E I need help https://njctl.org/video/?v=47F-oZ7cHGM AP Block Code Take a look at the code below. This is a form of AP Pseudocode that you will see on the AP test called Block Code. The AP pseudocode you have seen so far has all been text based. Block code is comprised of diagrams (like shown below). Let's read through it together to understand the meaning. https://njctl.org/video/?v=4vlUBjXiKKk AP Block Code Can you figure out what this will display? AP Block Code list holds the values 5, 10, 13, 0 sum is equal to 0 This line will go through each number in the list and set it equal to item, one at a time Adds the current value of item to whatever sum is, then sets sum equal to new value Once all the items from list have been added, display the sum Can you figure out what this will display? AP Pseudocode FOR EACH Loops We've seen and have worked with for loops but this code block uses what is called a FOR EACH loop. This can also, be written in text based code list [5, 10, 13, 0] sum 0 FOR EACH item IN list { sum sum + item } DISPLAY(sum) AP Pseudocode FOR EACH Loops FOR EACH loops and FOR loops work similarly but the main difference is that in a FOR EACH loop a list must be used and the variable item, in this case, is assigned each value in list as we iterate through the loop list [5, 10, 13, 0] The variable item is sum 0 automatically assigned FOR EACH item IN list the value of the first element in list. { sum sum + item The value stored in item is added to the } value stored in sum. DISPLAY(sum) sum is output and holds the sum of all the elements in list. 24 What will the following AP pseudocode display? A 5 Answer B 28 C 0 D Nothing Displays E I need help https://njctl.org/video/?v=ZcW1zQS8Mho 25 What will the following AP pseudocode display? A 24 Answer B 8 C 29 D Nothing Displays E I need help https://njctl.org/video/?v=RrSAt7cEUfI 26 What will the following AP pseudocode display? A 10 Answer B 20 C 0 D Nothing Displays E I need help https://njctl.org/video/?v=OSgki_EHbbo Adding to Lists Return to Table of Contents https://njctl.org/video/?v=LossRIZv7E0 Adding Elements at Anytime So far we have worked with predetermined lists. Meaning, we create the list with all its elements in it, then work with it. But, what if we wanted our list to change as we needed it to. Can you think of an example where we would need a list to continue to grow or change? A shopping list is a great example! At first, we may need only one or two items, then the list could grow. But how would we do this? Take a look at the list created below. What if we want to add "Peanut Butter" to the list later on in the program? cart = ["Milk", "Eggs"] print(cart) Syntax for.append( ) To add elements to the end of a list in Python you can use.append( ). The syntax for append() is as follows: listName.append(item) Name of List A period between list name and "append" Item to be added Adding Elements in Lists Let's go back to the cart and see how we can add Peanut Butter. cart = ["Milk", "Eggs"] print(cart) cart.append("Peanut Butter") print(cart) ['Milk', 'Eggs'] ## original items ['Milk', 'Eggs', 'Peanut Butter'] ## updated items “Peanut Butter” got added to the end of the list after "Eggs". Adding Elements in Lists Because we are able to add elements to a list at anytime, we are also able to begin with an empty list. An empty list is a list that has no elements in it. It can be written like: listName = [ ] Our last example could have been written like this instead: cart = [ ] cart.append("Milk") cart.append("Eggs") cart.append("Peanut Butter") print(cart) Which would have the same output: ['Milk', 'Eggs', 'Peanut Butter'] AP Pseudocode Adding Elements in Lists To add elements to the end of a list in AP Pseudocode you can use APPEND(). The syntax for APPEND() is as follows: APPEND(list, item) List to add the item APPEND Function Item to be added APPEND(list, item) increases the length of list by 1, and item is placed at the end of list. AP Pseudocode Adding Elements in Lists Below, we've created a list cart. Initially, cart has two elements stored in it. After we use the APPEND() function and display cart, "Peanut Butter" has been added to the end of cart. cart ["Milk", "Eggs"] DISPLAY(cart) APPEND(cart, "Peanut Butter") DISPLAY(cart) ['Milk', 'Eggs'] ## original items ['Milk', 'Eggs', 'Peanut Butter'] ## updated items https://njctl.org/video/?v=M__chEoK2e0 27 Which code snippet will add "Apples" to the end of list cart? A cart.append("Apples") Answer B cart[x] = "Apples" C cart = ("Apples") D cart.append(Apples) E I need help https://njctl.org/video/?v=vt3uJIXQYlc 28 What is the output of the following code? names = [ ] names.append("GoodBye") names.append("Hello") print( names ) Answer A ['Goodbye', 'Hello'] B ['Hello', 'Goodbye'] C Compiler error D ['Goodbye'] E I need help https://njctl.org/video/?v=piO1RFAIi3E 29 What is the output of the following Python code segment? count = [ ] count.append(5) A Answer count.append(3) B [ ] count.append(1) C [1, 3, 5] print(count) D [5, 3, 1] E I need help https://njctl.org/video/?v=VdyxCnXph3k 30 What is the output of the following AP Pseudocode segment? cart ["Eggs", "Butter"] APPEND(cart, "Lemonade") DISPLAY(cart) Answer A ['Eggs', 'Butter'] B [ ] C ['Eggs', 'Butter', 'Lemonade'] D ['Eggs', 'Lemonade'] E I need help https://njctl.org/video/?v=6gm3WWb5x74 Assigning Elements using Loops Let's say we want to have a list that looks like this: 0 1 2 3 4 5 We could fill the list altogether, as shown below... countDown = [0, 1, 2, 3, 4, 5] Or we can even add each element one at a time like this: countDown.append(0) countDown.append(1) countDown.append(2) countDown.append(3) countDown.append(4) countDown.append(5) https://njctl.org/video/?v=J73X9K9cGfg append( ) in Loops However, what if you wanted to create a list that stored 100 numbers. It would be very tedious to write all those out the way we just did. This is where append( ) and loops work very well together! Let's use a loop to fill in the numbers 1 - 5 into a list called countDown. First, create an empty list. countDown = [ ] We cannot use a for loop for this because there are no elements in our current list to traverse through. Instead we can use a while loop. append( ) in Loops countDown = [ ] a = 1 This variable represents the while a = 0: print(countDown[i]) i-=1 print("LAUNCH!") Could we have approached this program another way? https://njctl.org/video/?v=qjxhkAloFYY IDE; Live codeIt! //LIVE Here is the same program, but done in a slightly different way. Can you tell what changed? countDown = [ ] i = 0 while i < 5: countDown.append(5 - i) i+=1 i = 0 while i < 5: print(countDown[i]) i+=1 print("LAUNCH!") Printing Elements using Loops countDown = [ ] i = 0 while i < 5: countDown.append(5 - i) i+=1 i = 0 while i < 5: print(countDown[i]) i+=1 print("LAUNCH!") In this version, the first element of the list holds the value of 5 instead of 1, so the list looks like 5 4 3 2 1 codeIt!Now Write a program to fill a list with even numbers from 0 to 50 then print each number on its own line. https://njctl.org/video/?v=VX0ls3r-b8I codeIt!Now Possible Solution num = [ ] i = 0 while i len(longestWord): longestWord = x print("The longest word is " + longestWord)