In this lab, you are going to practice list operations introduced in the lecture and then explore a few more operations.
Exercise 1: Here are two similar questions. Write the code that would answer each:
doctor_who_actors = ["McGann","Eccleston","Tennant","Smith","Capaldi","Whittaker"]
Exercise 2: In the lecture, we discussed this code for removing values from a list. What if we want to remove the value from a specific day number (i.e., 0-6) rather than the amount of rainfall? Change the code to make it work in that case.
rainfall_amounts = [0.0, 0.3, 0.71, 0.0, 0.32, 1.1, 0.4]
val_to_remove = float(input("Enter a value to remove: "))
rainfall_amounts.remove(val_to_remove)
print(rainfall_amounts)
Exercise 3: Some operators might work with lists and some might not. For each of the following, try them out at the interactive shell and keep notes on which ones worked and which didn't. If it did work, make sure to write down what it did.
["A","B","C"]+["C","D"]
["A","B","C"]-["C","D"]
["A","B","C"]*["C","D"]
["A","B","C"]+5
["A","B","C"]*5
Exercise 4: You can put a list inside of another list (this is called a nested list). Try each of the lines below. In your notes, write down what happens when using two indices.
nested_list = [1,2,3,[4,5,6],7]
print(nested_list)
print(nested_list[2])
print(nested_list[3])
print(nested_list[3][1])
Challenge Exercise 5: Write code that will ask the user for a rainfall amount. If that amount appears in the list, tell them the day it occurred (i.e., the index of that item in the list). If it appears more than once, report the index of the first one. If it does not appear in the list, tell them that no day had that exact amount of rain. Use the list below as the rainfall amount list (it should be the first line in your code)
rainfall = [0.0, 0.3, 0.71, 0.0, 0.32, 1.1, 0.4]
Your output should look like this:
When you are finished, submit your solution to the Lab 7: Rainfall search assignment on codePost. It will be autograded, and it'll be looking for the output to match the examples above.