Question: Python Python Exercise 1 . Lists: Create a list of 5 of your favorite movies. Access the third movie in the list. Solution for Exercise

Python
Python
Exercise 1. Lists: Create a list of 5 of your favorite movies. Access the third movie in the list.
Solution for Exercise 1:
movies =["Movie1", "Movie2", "Movie3", "Movie4", "Movie5"]
print(movies[2])
Exercise 2. Modification: Add another movie to the list and then remove the second movie.
Solution for Exercise 2:
movies.append("Movie6")
del movies[1]
Exercise 3. Tuples: Create a tuple of 3 cities you'd love to visit. Why can't you change the second city?
Solution for Exercise 3:
cities =("Paris", "Tokyo", "Nairobi")
# cities[1]= "Berlin" # This would raise an error since tuples are immutable.
Exercise 4. Operations: For both your list and tuple, determine their lengths.
Solution for Exercise 4:
num_movies = len(movies)
print(num_movies)
num_cities =len(ccties)
print(num_cities)
Python Python Exercise 1 . Lists: Create a list

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 Programming Questions!