1
0

initial file upload

This commit is contained in:
mlot
2025-05-09 10:12:44 -04:00
parent 61bf543133
commit 40e9918df0
22 changed files with 215 additions and 1 deletions

9
chap3/bicycles.py Normal file
View File

@@ -0,0 +1,9 @@
bicycles = ['trek', 'cannondale', 'redline', 'specialized']
print(bicycles)
print(bicycles[-1])
print(bicycles[0].title())
message = f"My first bicycle was a {bicycles[2].title()}."
print(message)

22
chap3/cars.py Normal file
View File

@@ -0,0 +1,22 @@
cars = ['bmw', 'audi', 'toyota', 'subaru']
cars.sort()
print(cars)
cars.sort(reverse=True)
print(cars)
cars = ['bmw', 'audi', 'toyota', 'subaru']
print("\nHere is the original list:")
print(cars)
print("\nHere is the sorted list:")
print(sorted(cars))
print("\nHere is the original list again:")
print(cars)
cars.reverse()
print(cars)
length_cars = len(cars)
print(length_cars)

2
chap3/dinner_guests.py Normal file
View File

@@ -0,0 +1,2 @@
guest_list = ['Sir Paul McCartney', 'Kurt Harland', 'Gene Ween', 'Dean Ween']
print(f"{len(guest_list)} guests are being invited to dinner.")

40
chap3/guest_list.py Normal file
View File

@@ -0,0 +1,40 @@
guest_list = ['Sir Paul McCartney', 'Kurt Harland', 'Gene Ween', 'Dean Ween']
print(f"I cordially invite {guest_list[0]} to join me for dinner this evening.")
print(f"I cordially invite {guest_list[1]} to join me for dinner this evening.")
print(f"I cordially invite {guest_list[2]} to join me for dinner this evening.")
print(f"I cordially invite {guest_list[3]} to join me for dinner this evening.")
cannot_attend = guest_list.pop(3)
print(f"\nSadly, {cannot_attend} is unable to accept the dinner invite.")
guest_list.append('Stu Mackenzie')
print(f"I cordially invite {guest_list[0]} to join me for dinner this evening.")
print(f"I cordially invite {guest_list[1]} to join me for dinner this evening.")
print(f"I cordially invite {guest_list[2]} to join me for dinner this evening.")
print(f"I cordially invite {guest_list[3]} to join me for dinner this evening.")
print("\nA bigger table was found. Inviting more guests.")
guest_list.insert(0, 'Sir Ringo Starr')
guest_list.insert(2, 'John Paul Densmore')
print(f"I cordially invite {guest_list[0]} to join me for dinner this evening.")
print(f"I cordially invite {guest_list[1]} to join me for dinner this evening.")
print(f"I cordially invite {guest_list[2]} to join me for dinner this evening.")
print(f"I cordially invite {guest_list[3]} to join me for dinner this evening.")
print(f"I cordially invite {guest_list[4]} to join me for dinner this evening.")
print(f"I cordially invite {guest_list[5]} to join me for dinner this evening.")
print("\nThe table will not arrive in time, so guest list will be cut down to two.")
remove_guest1 = guest_list.pop(2)
remove_guest2 = guest_list.pop(2)
remove_guest3 = guest_list.pop(2)
remove_guest4 = guest_list.pop(2)
print(f"Sorry, {remove_guest1}, but I cannot invite you to dinner.")
print(f"Sorry, {remove_guest2}, but I cannot invite you to dinner.")
print(f"Sorry, {remove_guest3}, but I cannot invite you to dinner.")
print(f"Sorry, {remove_guest4}, but I cannot invite you to dinner.")
print(f"\nI still cordially invite {guest_list[0]} to join me for dinner this evening.")
print(f"I still cordially invite {guest_list[1]} to join me for dinner this evening.")
print("\nDeleting the guest list...")
del guest_list[0]
del guest_list[0]
print(guest_list)

View File

@@ -0,0 +1,8 @@
guest_list = ['Sir Paul McCartney', 'Kurt Harland', 'Gene Ween', 'Dean Ween']
print(guest_list[4])
# Traceback (most recent call last):
# File "intentional_error.py", line 2, in <module>
# print(guest_list[4])
# ~~~~~~~~~~^^^
# IndexError: list index out of range

28
chap3/motorcycles.py Normal file
View File

@@ -0,0 +1,28 @@
motorcycles = ['honda', 'yamaha', 'suzuki']
print(motorcycles)
motorcycles.append('honda')
motorcycles[0] = 'ducati'
print(motorcycles)
motorcycles.insert(0, 'harley')
print(motorcycles)
del motorcycles[0]
print(motorcycles)
popped_motorcycle = motorcycles.pop()
print(motorcycles)
print(popped_motorcycle)
print(f"The last motocycle I owned was a {popped_motorcycle.title()}.")
first_owned = motorcycles.pop(0)
print(f"The first motorcyle I owned was a {first_owned.title()}.")
motorcycles.remove('suzuki')
print(motorcycles)
too_expensive = 'yamaha'
motorcycles.remove(too_expensive)
print(f"{too_expensive.title()} is too expensive for me!")

13
chap3/names.py Normal file
View File

@@ -0,0 +1,13 @@
names = ['mike', 'josh', 'joe', 'jim', 'jason']
print(names[0])
print(names[1])
print(names[2])
print(names[3])
print(names[4])
print(f"Hello, {names[0].title()}. What's up with you?")
print(f"Hello, {names[1].title()}. What's up with you?")
print(f"Hello, {names[2].title()}. What's up with you?")
print(f"Hello, {names[3].title()}. What's up with you?")
print(f"Hello, {names[4].title()}. What's up with you?")

20
chap3/seeing_world.py Normal file
View File

@@ -0,0 +1,20 @@
places_visit = ['Jerusalem', 'London', 'Dublin', 'Tokyo', 'Nome']
print(places_visit)
print(sorted(places_visit))
print(places_visit)
print(sorted(places_visit, reverse=True))
print(places_visit)
places_visit.reverse()
print(places_visit)
places_visit.reverse()
print(places_visit)
places_visit.sort()
print(places_visit)
places_visit.sort(reverse=True)
print(places_visit)