This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Number is Integer or Float - return Absolute Function | |
# A Codecademy Python (Make a Payment: Run It) assignment | |
# Dr. Steven B. Combs, coding novice | |
def hotel_cost(nights): | |
return nights * 140 | |
bill = hotel_cost(5) | |
def add_monthly_interest(balance): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Number is Integer or Float - return Absolute Function | |
# A Codecademy Python (List Sort) assignment | |
# Dr. Steven B. Combs, coding novice | |
start_list = [5, 3, 1, 2, 4] # Existing list | |
square_list = [] # Placeholder for new list | |
for number in start_list: # Loop until no more items in list | |
square_list.append(number ** 2) # Square each item in the list and append to square_list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Number is Integer or Float - return Absolute Function | |
# A Codecademy Python (It's Dangerous to Go Alone! Take This) list and dictionary assignment | |
# Dr. Steven B. Combs, coding novice | |
inventory = {'gold' : 500, | |
'pouch' : ['flint', 'twine', 'gemstone'], # Assigned a new list to 'pouch' key | |
'backpack' : ['xylophone','dagger', 'bedroll','bread loaf']} | |
# Adding a key 'burlap bag' and assigning a list to it | |
inventory['burlap bag'] = ['apple', 'small ruby', 'three-toed sloth'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Print every definition in a dictionary | |
# A Codecademy Python (This is KEY!) assignment | |
# Dr. Steven B. Combs, coding novice | |
webster = { | |
"Aardvark" : "A star of a popular children's cartoon show.", | |
"Baa" : "The sound a goat makes.", | |
"Carpet": "Goes on the floor.", | |
"Dab": "A small amount." | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Print every definition in a dictionary | |
# A Codecademy Python (Control Flow and Looping) assignment | |
# Dr. Steven B. Combs, coding novice | |
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] | |
for number in a: | |
if number % 2 == 0: # If divisible by two, the number is even | |
print number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Print every definition in a dictionary | |
# A Codecademy Python (List + Functions) assignment | |
# Dr. Steven B. Combs, coding novice | |
zz = ["fizz","buzz","fizz"] # zz word list | |
fizz_count(zz) # Pass the zz word list to fizz_count function | |
def fizz_count(zz): # Defines the fizz_count function | |
count = 0 # Intialize variable and set to 0 | |
for string in zz: # Step through zz list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Print Inventory and Cost of Fruit | |
# A Codecademy Python (Keeping Track of Produce) assignment | |
# Dr. Steven B. Combs, coding novice | |
for cost in prices: | |
print cost | |
print "price: " + str(prices[cost]) | |
print "stock: " + str(stock[cost]) | |
prices = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Print the total value of the fruit inventory | |
# A Codecademy Python (Something of Value) assignment | |
# Dr. Steven B. Combs, coding novice | |
total = 0 # Initialize variable to 0, required if code run more than once | |
for x in prices: # Step through each definintion in the prices and stock dictionaries | |
subtotal = prices[x] * stock[x] # Compute value of number of stock times individual cost | |
total += subtotal # Add the subtotal of each pair to the total (same as total=total+subtotal) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Computer the bill for a shopping list | |
# A Codecademy Python (Making a Purchase) assignment | |
# Dr. Steven B. Combs, coding novice | |
groceries = ["banana", "orange", "apple"] | |
stock = { | |
"banana": 6, | |
"apple": 0, | |
"orange": 32, |