diff --git a/README.md b/README.md index c5a4993..65562a3 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # pythonCrashCourse -Python Crash Course Book Exercise and Projects Practice \ No newline at end of file +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. \ No newline at end of file diff --git a/chap1/hello_world.py b/chap1/hello_world.py new file mode 100644 index 0000000..e008ec3 --- /dev/null +++ b/chap1/hello_world.py @@ -0,0 +1 @@ +print("Hello Python World!") diff --git a/chap2/apostrophe.py b/chap2/apostrophe.py new file mode 100644 index 0000000..9152457 --- /dev/null +++ b/chap2/apostrophe.py @@ -0,0 +1,2 @@ +message = "One of Python's strengths is its diverse community." +print(message) \ No newline at end of file diff --git a/chap2/comment.py b/chap2/comment.py new file mode 100644 index 0000000..820f150 --- /dev/null +++ b/chap2/comment.py @@ -0,0 +1,2 @@ +# Say hello to everyone +print("Hello Python People!") \ No newline at end of file diff --git a/chap2/famous_quote.py b/chap2/famous_quote.py new file mode 100644 index 0000000..6b51120 --- /dev/null +++ b/chap2/famous_quote.py @@ -0,0 +1 @@ +print('Douglas Adams once said, "We are stuck with technology when what we really want is just stuff that works."') \ No newline at end of file diff --git a/chap2/famous_quote2.py b/chap2/famous_quote2.py new file mode 100644 index 0000000..2505d8a --- /dev/null +++ b/chap2/famous_quote2.py @@ -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) \ No newline at end of file diff --git a/chap2/file_extensions.py b/chap2/file_extensions.py new file mode 100644 index 0000000..856149c --- /dev/null +++ b/chap2/file_extensions.py @@ -0,0 +1,2 @@ +filename = "python_notes.txt" +print(filename.removesuffix('.txt')) \ No newline at end of file diff --git a/chap2/full_name.py b/chap2/full_name.py new file mode 100644 index 0000000..77adc2f --- /dev/null +++ b/chap2/full_name.py @@ -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) \ No newline at end of file diff --git a/chap2/hello_world.py b/chap2/hello_world.py new file mode 100644 index 0000000..82890eb --- /dev/null +++ b/chap2/hello_world.py @@ -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) \ No newline at end of file diff --git a/chap2/name.py b/chap2/name.py new file mode 100644 index 0000000..018f38d --- /dev/null +++ b/chap2/name.py @@ -0,0 +1,6 @@ +name = "ada lovelace" +print(name.title()) + +name = "Ada Lovelace" +print(name.upper()) +print(name.lower()) \ No newline at end of file diff --git a/chap2/name_cases.py b/chap2/name_cases.py new file mode 100644 index 0000000..8487dd6 --- /dev/null +++ b/chap2/name_cases.py @@ -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()) \ No newline at end of file diff --git a/chap2/numbers.py b/chap2/numbers.py new file mode 100644 index 0000000..0ec41a1 --- /dev/null +++ b/chap2/numbers.py @@ -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}") \ No newline at end of file diff --git a/chap2/personal_message.py b/chap2/personal_message.py new file mode 100644 index 0000000..084c323 --- /dev/null +++ b/chap2/personal_message.py @@ -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?") \ No newline at end of file diff --git a/chap2/stripping_names.py b/chap2/stripping_names.py new file mode 100644 index 0000000..9f23ce9 --- /dev/null +++ b/chap2/stripping_names.py @@ -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}") \ No newline at end of file diff --git a/chap3/bicycles.py b/chap3/bicycles.py new file mode 100644 index 0000000..8b7bc85 --- /dev/null +++ b/chap3/bicycles.py @@ -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) \ No newline at end of file diff --git a/chap3/cars.py b/chap3/cars.py new file mode 100644 index 0000000..4965fa5 --- /dev/null +++ b/chap3/cars.py @@ -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) \ No newline at end of file diff --git a/chap3/dinner_guests.py b/chap3/dinner_guests.py new file mode 100644 index 0000000..27adf3d --- /dev/null +++ b/chap3/dinner_guests.py @@ -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.") \ No newline at end of file diff --git a/chap3/guest_list.py b/chap3/guest_list.py new file mode 100644 index 0000000..89f4e59 --- /dev/null +++ b/chap3/guest_list.py @@ -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) \ No newline at end of file diff --git a/chap3/intentional_error.py b/chap3/intentional_error.py new file mode 100644 index 0000000..ecaae99 --- /dev/null +++ b/chap3/intentional_error.py @@ -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 +# print(guest_list[4]) +# ~~~~~~~~~~^^^ +# IndexError: list index out of range \ No newline at end of file diff --git a/chap3/motorcycles.py b/chap3/motorcycles.py new file mode 100644 index 0000000..0c89a71 --- /dev/null +++ b/chap3/motorcycles.py @@ -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!") \ No newline at end of file diff --git a/chap3/names.py b/chap3/names.py new file mode 100644 index 0000000..ac1adb8 --- /dev/null +++ b/chap3/names.py @@ -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?") \ No newline at end of file diff --git a/chap3/seeing_world.py b/chap3/seeing_world.py new file mode 100644 index 0000000..5bad6a2 --- /dev/null +++ b/chap3/seeing_world.py @@ -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) \ No newline at end of file