List Methods (2)
Most list methods will change the list they're called on. Examples are:
.append(), that adds an element to the list it is called on,.remove(), that removes the first element of a list that matches the input, and.reverse(), that reverses the order of the elements in the list it is called on.
You'll be working on the list with the area of different parts of the house: areas.
This exercise is part of the course
Introduction to Python
Exercise instructions
- Use
.append()twice to add the size of the poolhouse and the garage again:24.5and15.45, respectively. Make sure to add them in this order. - Print out
areas - Use the
.reverse()method to reverse the order of the elements inareas. - Print out
areasonce more.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create list areas
areas = [11.25, 18.0, 20.0, 10.75, 9.50]
# Use append twice to add poolhouse and garage size
# Print out areas
# Reverse the orders of the elements in areas
# Print out areas