Compare commits

...

23 Commits

Author SHA1 Message Date
cheeks
733840f08c Completed 8-14 Cars 2025-02-21 14:41:04 +00:00
cheeks
1232748641 Completed 8-14 Cars 2025-02-21 14:41:04 +00:00
cheeks
2361964f0b Test 2025-02-21 14:41:04 +00:00
cheeks
0747a95612 Test 2025-02-21 14:41:04 +00:00
cheeks
3501c6468f Completed Exercise 8-14 Cars 2025-02-21 14:41:04 +00:00
cheeks
9e835ac2c4 Completed Exercise 8-13 User Profiles 2025-02-21 14:41:04 +00:00
cheeks
a3aa5c7bf8 Completed 8-12 Sandwiches 2025-02-21 14:41:04 +00:00
cheeks
30c400a26c Completed Exercise 8-11 Archived Messages 2025-02-21 14:41:04 +00:00
cheeks
8b0b47f669 Completed Exercise 8-10 Sending Messages 2025-02-21 14:41:04 +00:00
cheeks
fe4c1c46b6 Completed exercise 8-9 Messages 2025-02-21 14:41:04 +00:00
cheeks
6353c96f05 Updated bookmark.md 2025-02-21 14:41:04 +00:00
cheeks
281ba37969 Update bookmark.md 2025-02-21 14:41:04 +00:00
cheeks
56b874a741 Completed Exercise 8-8 User Albums 2025-02-21 14:41:04 +00:00
cheeks
3d627eed66 Completed Exercise 8-7 Album 2025-02-21 14:41:04 +00:00
cheeks
51e6ca4dac Completed Exercise 8-6 City Names 2025-02-21 14:41:04 +00:00
cheeks
addb79e561 File name corrections 2025-02-21 14:41:04 +00:00
cheeks
0f3a8794ea Completed Exercise 8-5 Cities 2025-02-21 14:41:04 +00:00
cheeks
766e35dbb5 Updated bookmark.md 2025-02-21 14:41:04 +00:00
cheeks
26590853a0 Completed Exercise 8-4 Large Shirts 2025-02-21 14:41:04 +00:00
cheeks
0c8ecca929 Completed Exercise 8-3 T-Shirt 2025-02-21 14:41:04 +00:00
cheeks
3b99e90ce1 Updated bookmark.md 2025-02-21 14:41:03 +00:00
cheeks
b9536440c3 Completed / RRenamed Exercise 8-2 Favorite Book 2025-02-21 14:41:00 +00:00
cheeks
aca9c8567f fixed typos 2025-02-21 14:40:21 +00:00
15 changed files with 205 additions and 1 deletions

View File

@ -0,0 +1,10 @@
# Exercise 8-2 Favorite Book
# Learning Objective: Create a function that takes one argument.
title = input("What is a good book?")
def favorite_book(title):
print(f"One of my favorite books is {title}")
favorite_book(title)

View File

@ -0,0 +1,7 @@
# Exercise 8-3 T-Shirt
# Learning Objective: Write a function with 2 arguments.
def make_shirt(size='S', message='your text here'):
print(f"\tNew shirt to be made:\n\tSIZE: {size}\n\tMESSAGE: {message}")
make_shirt("L", "Hello Python World")

View File

@ -0,0 +1,8 @@
# Exercise 8-4 Large Shirts
# Learning Objective: Create function with default values.
def make_shirt(size='L', message='I love Python'):
print(f"\tNew shirt to be made:\n\tSIZE: {size}\n\tMESSAGE: {message}")
make_shirt("M", "Hello Python World")
make_shirt()

View File

@ -0,0 +1,9 @@
# Exercise 8-5 Cities
# Learning Objective: Write a function that has a default value. Call it three times.
def describe_city(city, country='United States'):
print(f'{city.title()} is in {country.title()}')
describe_city('Chicago')
describe_city('Annapolis')
describe_city('Paris', 'France')

View File

@ -0,0 +1,11 @@
# Exercise 8-6 City Names
# Learning Objective: Create function that returns a value
def city_country(city_name, country):
return f"{city_name.title()}, {country.title()}"
#Call 3 Times
print(city_country('Paris', 'France'))
print(city_country('Hamburg', 'Germany'))
print(city_country('Portland', 'United States'))

17
Chapter_08/8-07_album.py Normal file
View File

@ -0,0 +1,17 @@
# Exercise 8-7 Album
# Learning Objective: Write a function that returns a dictionary of information about an album.
def make_album(artist_name, album_title, num_tracks=None):
album_info = {'artist': artist_name, 'album': album_title}
if num_tracks:
album_info['number_of_tracks'] = num_tracks
return album_info
newAlbum = make_album('Korn', "Y'all wanna single", 1)
print(newAlbum)
newAlbum2 = make_album('Infected Mushroom', 'Classical Mushroom', 9)
print(newAlbum2)
newAlbum3 = make_album('Outsiders, Menog', 'Psychedelic Liquid')
print(newAlbum3)

View File

@ -0,0 +1,32 @@
# Exercise 8-8 User Albums
# Learning Objective: Write a function with a while loop that gathers input and returns a dictionary of information about an album.
# VERY MESSY
def make_album(artist_name, album_title, num_tracks=None):
album_info = {'artist': artist_name, 'album': album_title}
if num_tracks:
album_info['number_of_tracks'] = num_tracks
return album_info
while True:
print("Welcome, entering 'q' will quit this program... \n")
gathered_artist = input("Please enter your artist: ")
if gathered_artist == 'q':
break
gathered_album = input("Now enter the album name: ")
if gathered_album == 'q':
break
desired_info = make_album(gathered_artist, gathered_album)
print(desired_info)
'''
newAlbum = make_album('Korn', "Y'all wanna single", 1)
print(newAlbum)
newAlbum2 = make_album('Infected Mushroom', 'Classical Mushroom', 9)
print(newAlbum2)
newAlbum3 = make_album('Outsiders, Menog', 'Psychedelic Liquid')
print(newAlbum3)
'''

View File

@ -0,0 +1,10 @@
# Exercise 8-9 Messages
# Learning Objective: Pass a list to a function.
texts = ['hello', 'how are you?', 'i am well thanks']
def show_messages(messages):
for message in messages:
print(message)
show_messages(texts)

View File

@ -0,0 +1,24 @@
# Exercise 8-10 Sending Messages
# Learning Objective: Manipulate a list from withim a function.
texts = ['message one', 'message two', 'message three']
sent_messages = []
def show_messages(messages):
for message in messages:
print(message)
def send_message(some_messages):
while some_messages:
to_be_sent = some_messages.pop()
sent_messages.append(to_be_sent)
print(f'{to_be_sent} has been sent')
#show_messages(texts)
send_message(texts)
print("SENT MESSAGES:\n")
print(sent_messages)
print('\nTEXTS:\n')
print(texts)

View File

@ -0,0 +1,24 @@
# Exercise 8-11 Archived Messages
# Learning Objective: Prevent the modification but act upon a list within a function
texts = ['message one', 'message two', 'message three']
sent_messages = []
def show_messages(messages):
for message in messages:
print(message)
def send_message(some_messages):
while some_messages:
to_be_sent = some_messages.pop()
sent_messages.append(to_be_sent)
print(f'{to_be_sent} has been sent')
#show_messages(texts)
send_message(texts[:])
print("SENT MESSAGES:\n")
print(sent_messages)
print('\nTEXTS:\n')
print(texts)

View File

@ -0,0 +1,20 @@
# Exercise 8-12 Sandwiches
# Learning Objective: Create a function that accepts arbitrary number of arguments.
order = []
ordering = True
print("Enter each ingredient one by one and hit enter. WHEN DONE type DONE to stop and process your order.")
while ordering == True:
sandwich_item = input("What can I add to your sandwich: \n")
if sandwich_item.lower() == 'done':
ordering = False
print("\tAdding {sandwich_item} to your sandwich...\n")
order.append(sandwich_item)
print(f"ORDER COMPLETE\nYou've ordered the following:\t")
for ingredient in order:
print(ingredient.lower())

View File

@ -0,0 +1,16 @@
# Exercise 8-13 User Profile
# Learning Objective: Create a function that takes in two predefined key-value pairs and add 3 arbitrary ones.
# user_profile.py
def build_profile(first, last, **user_info):
"""Build a dictionary containing everything we know about a user."""
user_info['first_name'] = first
user_info['last_name'] = last
return user_info
user_profile = build_profile('mister', 'cheeks',
location='united states',
favorite_color='orange',
favorite_meal='scrambled eggs')
print(user_profile)

15
Chapter_08/8-14_cars.py Normal file
View File

@ -0,0 +1,15 @@
# Exercise 8-14 Cars
# Learning Objective: Make a function that contains a dictionary and allows arbitrary numbers of arguments
# with two expected arguments of Manufacturer and Model Name
def make_car(make, model, **car_info):
car_info['Manufacturer'] = make
car_info['Model'] = model
return car_info
my_car = make_car('nissan', 'z', color='red', transmission='manual', rubber_floor_mats=True)
print(my_car)

View File

@ -1,2 +1,3 @@
## Left off: ## Left off:
### Chapter 8: Functions ### Chapter 8: Try It Yourself: 8-9 Messages