python/motorcycles.py

76 lines
2.0 KiB
Python

# creating a list of motorcycles, then printing the list
#motorcycles = ['honda', 'yamaha', 'suzuki']
#print(motorcycles)
# printing the first element in the list
#motorcycles[0] = 'ducati'
#print(motorcycles)
# appending a new item to the list
#motorcycles.append('ducati')
#print(motorcycles)
# starting with an empty list, then adding to it using a series of append
# statements
#motorcycles = []
#motorcycles.append('honda')
#motorcycles.append('yamaha')
#motorcycles.append('suzuki')
#print(motorcycles)
# inserting an element at the beginning of a list
#motorcycles = ['honda', 'yamaha', 'suzuki']
#motorcycles.insert(0, 'ducati')
#print(motorcycles)
# deleting an element from a list; in the example below, we're deleting the 2nd element from the list of motorcycles
#motorcycles = ['honda', 'yamaha', 'suzuki']
#del motorcycles[1]
#print(motorcycles)
# popping an element from the end of a list, then being able to use that element afterwards
#motorcycles = ['honda', 'yamaha', 'suzuki']
#print(motorcycles)
#popped_motorcycles = motorcycles.pop()
#print(popped_motorcycles)
# printing the last-owned motorcycle as a statement
#motorcycles = ['honda', 'yamaha', 'suzuki']
#last_owned = motorcycles.pop()
#print(f"The last motorcycle I owned was a {last_owned}.")
# printing the first-owned motorcycle as a statement
#motorcycles = ['honda', 'yamaha', 'suzuki']
#first_owned = motorcycles.pop(0)
#print(f"The first motorcycle I owned was a {first_owned}.")
# removing an item from a list based on its value rather than its position
#motorcycles = ['honda', 'yamaha', 'ducati', 'suzuki']
#print(motorcycles)
#motorcycles.remove('ducati')
#print(motorcycles)
# printing a statement about a particular element of a motorcycle list that's too expensive for the owner
motorcycles = ['honda', 'yamaha', 'ducati', 'suzuki']
print(motorcycles)
too_expensive = 'ducati'
motorcycles.remove(too_expensive)
print(motorcycles)
print(f"\nThe {too_expensive.title()} is just too expensive for me.")