Question: Introduction In this lab you will develop a deeper understanding of lists, ranges and for loops. First let's look at how to create a list.

 Introduction In this lab you will develop a deeper understanding oflists, ranges and for loops. First let's look at how to createa list. You can create a list by simply assigning it values

Introduction In this lab you will develop a deeper understanding of lists, ranges and for loops. First let's look at how to create a list. You can create a list by simply assigning it values as we did with WORDLIST in ex17_word_jumble.py as follows: WORDLIST = ["python","jumble","trombone", "difficult","answer","xylophone"] However, you can also create a list "on the fly" by using the append function for lists. Here are a couple examples: numberList = [] for i in range(10): numberList.append(i) print (numberList) numList = [] numElements = int(input ("How many numbers are in your list? ")) for index in range (numElements): num = int(input("What number do you want at position "+str(index)+"? ")) numList.append(num) print(numList) I encourage you to read this code carefully and type it in and run it. Make sure you understand how range and append work. You can see the first loop just puts the numbers 0 through 9 into positions 0 through 9 in the list. The second loop asks the user how many elements there will be in the list and then asks for each number one at a time to append to the list. Lists and Functions 1. Create a function called filllist. This function should take three parameters: (a) a list (b) the number of elements you want in the list (c) the starting value of the numbers in the list. The function should fill the list with the numbers starting at given value. For example, if I call filllist(numList, 10, 100) then the number 100 should be in position 0 of the list, the number 101 should be in position 1 of the list and so on until the number 109 is in position 9 of the list. Use a for loop and the range function to fill the list (similar to the first for loop above). Finally, when you're done filling the list the function should return. You should not return any values from this function. 2. Add the following three lines to your main program. The first line declares a list in the main program. The second line calls the function. Notice how you simply call the function on a line of code all by itself. Finally, print the entire list. numList1 = [] fillList(numList1, 10, 100) print (numList1) Because lists are mutable that means that when you pass the list to the function you're actually passing a reference to the list and not the list itself. Thus, when you modify the list in the function, the list you created in the main program is altered as well. No other data type that we've seen so far works this way. Ask your TA if you have questions about the mutability of lists. 3. Create a new list, call it numList2, and fill this list with 10 numbers starting at 200 by calling fililist again. After you call the function, print this list in the main program. 4. Now write a function called addListToList that takes two lists with the same number of elements. This function will create a new list by adding the values in the same position at each list that was passed to it. I want you to use a for loop with the range function to do this. Finally this function will return the new list you just created. For example, if the first list passed is 10 numbers starting at 100 like this: 100 101 102 103 104 105 106 107 108 109 and the second list passed is 10 numbers starting a 200 like this: 200 201 202 203 204 205 206 207 208 209 Then the list that is returned should be a list of 10 numbers like this: 300 302 304 306 308 310 312 314 316 318 5. Modify your main program to call the addListToList function. Notice when you call this function, since it returns a list, you will have to receive a list in the main part of the program. Finally, print out the list that is returned and verify that it is correct. Turn-in Details Be sure your file is named lastname_firstname_lab7.py and is turned in on Canvas by Friday. Grading Rubric fillList function is correct and uses a for loop and the range function. (4 points) fililist is called correctly from the main part of the program and the list is printed out (1 point) addListToList function is correct and uses a for loop and the range function (4 points) addListToList is called correctly from the main part of the program and the resulting list is printed (1 point) Well done! You have completed Lab 7. Feel free to work on hw3 for the rest of the lab period

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!