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

View File

@@ -1,3 +1,7 @@
# pythonCrashCourse
Python Crash Course Book Exercise and Projects Practice
Python Crash Course Book Exercise and Projects Repository
These may or may not be completely correct or the simplest way, but these are some of the exercises I practiced from the book **"Python Crash Course (3rd Edition)"** by [Eric Matthes](https://ehmatthes.github.io/pcc_3e/).
I originally learned the basics of Python back in 2016 using the book "_Automate the Boring Stuff with Python_" by [Al Sweigart](https://automatetheboringstuff.com/). Over time my redimentary Python skills faded as I focused more on Powershell for Windows sysadmin stuff. Now that I'm beginning to move away from Windows environments and back into Linux, I wanted to brush up on my foundational Python skills again and relearn the basics.

1
chap1/hello_world.py Normal file
View File

@@ -0,0 +1 @@
print("Hello Python World!")

2
chap2/apostrophe.py Normal file
View File

@@ -0,0 +1,2 @@
message = "One of Python's strengths is its diverse community."
print(message)

2
chap2/comment.py Normal file
View File

@@ -0,0 +1,2 @@
# Say hello to everyone
print("Hello Python People!")

1
chap2/famous_quote.py Normal file
View File

@@ -0,0 +1 @@
print('Douglas Adams once said, "We are stuck with technology when what we really want is just stuff that works."')

3
chap2/famous_quote2.py Normal file
View File

@@ -0,0 +1,3 @@
famous_person = "Douglas Adams"
message = f'{famous_person} once said, "We are stuck with technology when what we really want is just stuff that works."'
print(message)

2
chap2/file_extensions.py Normal file
View File

@@ -0,0 +1,2 @@
filename = "python_notes.txt"
print(filename.removesuffix('.txt'))

15
chap2/full_name.py Normal file
View File

@@ -0,0 +1,15 @@
first_name = "ada"
last_name = "lovelace"
full_name = f"{first_name} {last_name}"
print(full_name)
first_name = "ada"
last_name = "lovelace"
full_name = f"{first_name} {last_name}"
print(f"Hello, {full_name.title()}!")
first_name = "ada"
last_name = "lovelace"
full_name = f"{first_name} {last_name}"
message = f"Hello, {full_name.title()}!"
print(message)

12
chap2/hello_world.py Normal file
View File

@@ -0,0 +1,12 @@
message = "Hello Python World!"
print(message)
mesage = "Hello Python Crash Course World!"
print(mesage)
# Try It Yourself pg. 19
message_alert1 = "This is a test of the emergency broadcast system."
print(message_alert1)
message_alert1 = "This is only a test."
print(message_alert1)

6
chap2/name.py Normal file
View File

@@ -0,0 +1,6 @@
name = "ada lovelace"
print(name.title())
name = "Ada Lovelace"
print(name.upper())
print(name.lower())

6
chap2/name_cases.py Normal file
View File

@@ -0,0 +1,6 @@
# This program takes the name assigned to a variable and prints it out in upper, lower, and title cases
first_name = "Barb"
print(first_name.upper())
print(first_name.lower())
print(first_name.title())

7
chap2/numbers.py Normal file
View File

@@ -0,0 +1,7 @@
print(2*4)
print(16/2)
print(9-1)
print(5+3)
my_fav_num = 7
print(f"My favorite number is {my_fav_num}")

View File

@@ -0,0 +1,4 @@
# This program assigns the name Ted to a variable and includes in a formatted print to stout
first_name = "Ted"
print(f"Hello {first_name}, would you like to learn some Python today?")

7
chap2/stripping_names.py Normal file
View File

@@ -0,0 +1,7 @@
persons_name = " Douglas Adams "
print(persons_name)
print(persons_name.lstrip())
print(persons_name.rstrip())
print(persons_name.strip())
print(f"{persons_name}\n")
print(f"\t{persons_name}")

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)