Thursday, July 31, 2014

Day 117

Python at CodeCademy. Worked on Python tutorial 6 of 7, Taking a Vacation: Pull it Together!
Worked on more defining functions that accept strings as an arguments.

The code used:
def hotel_cost(nights):
    return 140 * nights
   
def plane_ride_cost(city):
    if city == "Charlotte":
        return 183
    elif city == "Tampa":
        return 220
    elif city == "Pittsburgh":
        return 222
    elif city == "Los Angeles":
        return 475
       
def rental_car_cost(days):
    if days >= 7:
        return days * 40 - 50
    elif days >= 3:
        return days * 40 - 20
    else:
        return days * 40
       
def trip_cost(city, days):
    return plane_ride_cost(city) + rental_car_cost(days) + hotel_cost(days)


There was no interaction for this code:

Wednesday, July 30, 2014

Day 116

Python at CodeCademy. Worked on Python tutorial 4 of 7, Taking a Vacation: Transportation!
Worked on more defining functions that accept strings as an arguments.

The code used:
def hotel_cost(nights):
    return 140 * nights
    
def plane_ride_cost(city):
    if city == "Charlotte":
        return 183
    elif city == "Tampa":
        return 220
    elif city == "Pittsburgh":
        return 222
    elif city == "Los Angeles":
        return 475
        
def rental_car_cost(days):
    if days >= 7:
        return days * 40 - 50
    elif days >= 3:
        return days * 40 - 20
    else:
        return days * 40

There was no interaction for this code:

Tuesday, July 29, 2014

Day 115

Python at CodeCademy. Worked on Python tutorial 3 of 7, Taking a Vacation: Getting There!
Worked on defining functions that accept a string as an argument.

The code used:
def hotel_cost(nights):
    return 140 * nights
def plane_ride_cost(city):
    if city == "Charlotte":
        return 183

    elif city == "Tampa":
        return 220

    elif city == "Pittsburgh":
        return 222

    elif city == "Los Angeles":
        return 475

There was no interaction for this code:

Monday, July 28, 2014

Day 114

Python at CodeCademy. Worked on Python tutorial 2 of 7, Taking a Vacation: Before Planning Your Trip! Did some refreshing on how functions are defined..

The code used:
def hotel_cost(nights):
    return 140.00 * nights

There was no interaction for this code:

Sunday, July 27, 2014

Day 113

Python at CodeCademy. Worked on Python tutorial 1 of 7, Taking a Vacation: Before We Begin! Reviewed built-in functions.

The code used:
def answer ():
    return (42)

There was no interaction for this code:

Saturday, July 26, 2014

Day 112

Python at CodeCademy. Worked on Python tutorial 19 of 19, Functions, Review: Built-In Functions! Completed tutorial by reviewing the built-in functions I was previously working with.

The code used:
def distance_from_zero(a):

    if type(a) == int or type(a) == float:
        return abs(a)
    else:
        return 'Nope'

There was no interaction for this code:

Friday, July 25, 2014

Day 111

Python at CodeCademy. Worked on Python tutorial 18 of 19, Functions, Review: Functions! Reviewed the modules I was previously working with.

The code used:
from math import sqrt
root = sqrt(13689)
print root

The code for this interaction:
117.0

Thursday, July 24, 2014

Day 110

Python at CodeCademy. Worked on Python tutorial 17 of 19, Functions, Review: Functions! Reviewed the functions I was previously working with.

The code used:
def shut_down(s):
    return shut_down
    
if shut_down == "yes":
    shut_down("Shutting down")
    
elif shut_down == "no":
    shut_down("Shutdown aborted")
    
else:
    shut_down("Sorry")

There was no code for this interaction:

Wednesday, July 23, 2014

Day 109

Python at CodeCademy. Worked on Python tutorial 16 of 19, Functions, type()! Worked on the type() function.

The code used:
print type(42) 
print type(4.2) 
print type('spam')

The code for this interaction:
<type 'int'>
<type 'float'>
<type 'str'>

Tuesday, July 22, 2014

Day 108

Python at CodeCademy. Worked on Python tutorial 15 of 19, Functions, abs()! Worked on the abs() function.

The code used:
absolute = abs(-42)
print absolute

The code for this interaction:
42

Monday, July 21, 2014

Day 107

Python at CodeCademy. Worked on Python tutorial 14 of 19, Functions, min()! Worked on the min() function.

The code used:
minimum = min(-1,0,1)
print minimum

The code for this interaction:
-1

Sunday, July 20, 2014

Day 106

Python at CodeCademy. Worked on Python tutorial 13 of 19, Functions, max()! Worked on the max() function.

The code used:
maximum = max(2,4,6)
print maximum

The code for this interaction:
6

Saturday, July 19, 2014

Day 105

Python at CodeCademy. Worked on Python tutorial 12 of 19, Functions, On Beyond Strings! Checked out some built-in functions.

The code used:
def biggest_number(*args):
    print max(args)
    return max(args)
    
def smallest_number(*args):
    print min(args)
    return min(args)

def distance_from_zero(arg):
    print abs(arg)
    return abs(arg)

biggest_number(-10, -5, 5, 10)
smallest_number(-10, -5, 5, 10)
distance_from_zero(-10)

The code for this interaction:
10
-10
10

Friday, July 18, 2014

Day 104

Python at CodeCademy. Worked on Python tutorial 11 of 19, Functions, Here Be Dragons! Checked out everything available in the math module.

The code used:
import math            # Imports the math module
everything = dir(math) # Sets everything to a list of things from math
print everything       # Prints 'em all!

The code for this interaction:
'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'hypot', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']

Thursday, July 17, 2014

Day 103

Python at CodeCademy. Worked on Python tutorial 10 of 19, Functions, Function Imports! Worked on Universal imports.

The code used:
from math import *

There was no interaction for this code:

Day 102

Python at CodeCademy. Worked on Python tutorial 9 of 19, Functions, Function Imports! Worked on function imports.

The code used:
from math import sqrt

There was no interaction for this code:

Tuesday, July 15, 2014

Day 101

Python at CodeCademy. Worked on Python tutorial 8 of 19, Functions, Generic Imports! Worked on generic imports.

The code used:
import math
print math.sqrt(25) 

The interaction for this code looked like this:
5.0

Monday, July 14, 2014

Day 100

Python at CodeCademy. Worked on Python tutorial 7 of 19, Functions, I Know Kung Fu! Testing what Python knows about square roots.

The code used:
print sqrt(25)

The interaction for this code looked like this:
Traceback (most recent call last):
File "python", line 3, in <module>
NameError: name 'sqrt' is not defined

Sunday, July 13, 2014

Day 99

Python at CodeCademy. Worked on Python tutorial 6 of 19, Functions, Practice Makes Perfect! Worked some more with functions.

The code used:
def cube(number):
    return number**3

def by_three(number):
    if number % 3 == 0:
        return cube(number)
    else:
        return False

There was no interaction for this code:

Saturday, July 12, 2014

Day 98

Python at CodeCademy. Worked on Python tutorial 5 of 19, Functions, Functions Calling Functions! Worked on functions calling other functions.

The code used:
def one_good_turn(n):
    return n + 1
    
def deserves_another(n):
    return one_good_turn(n) + 2

There was no interaction for this code:

Friday, July 11, 2014

Day 97

Python at CodeCademy. Worked on Python tutorial 4 of 19, Functions, Parameters and Arguments! Worked on Parameters and Arguments.

The code used:
def power(base, exponent):
    result = base**exponent
    print "%d to the power of %d is %d." % (base, exponent, result)

power(37, 4)  

The interaction for this code looked like this:
37 to the power of 4 is 1874161.

Thursday, July 10, 2014

Day 96

Python at CodeCademy. Worked on Python tutorial 3 of 19, Functions, Call and Response! Worked on defining a function and calling it to be implemented.

The code used:def spam():
def square(n):
    """Returns the square of a number."""
    squared = n**2
    print "%d squared is %d." % (n, squared)
    return squared
square(10)

The interaction for this code looked like this:
10 squared is 100.

Wednesday, July 9, 2014

Day 95

Python at CodeCademy. Worked on Python tutorial 2 of 19, Functions, Function Junction? Created a function, spam, that prints the string "Eggs!" to the console. Don't forget to include a comment of your own choosing (enclose it in triple quotes!).

The code used:
def spam():
    """Prints 'Eggs to the console."""
    print "Eggs!"
    
# Define the spam function above this line.
spam()

The interaction for this code looked like this:
Eggs!

Tuesday, July 8, 2014

Day 94

Python at CodeCademy. Worked on Python tutorial 1 of 19, Functions, What Good are Functions? Checked out the code in the editor. Saw how much of the code I understand at first glance.

The code used:
def tax(bill):
    """Adds 8% tax to a restaurant bill."""
    bill *= 1.08
    print "With tax: %f" % bill
    return bill

def tip(bill):
    """Adds 15% tip to a restaurant bill."""
    bill *= 1.15
    print "With tip: %f" % bill
    return bill
    
meal_cost = 100
meal_with_tax = tax(meal_cost)
meal_with_tip = tip(meal_with_tax)

The interaction for this code looked like this:
With tax: 108.000000
With tip: 124.200000

Monday, July 7, 2014

Day 93

Python at CodeCademy. Worked on Python tutorial 11 of 11, PygLatin, Testing, Testing, is This Thing On? Completed tutorial and tested out the code.

The code used:
pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
    word = original.lower()
    first = word[0]
    new_word = word + first + pyg
    new_word = new_word[1:len(new_word)]
    print new_word
else:
    print 'empty'

The interaction for this code looked like this:
Enter a word: Pig
igpay

Enter a word: Latin
atinlay

Enter a word: 123
empty

Sunday, July 6, 2014

Day 92



Python at CodeCademy. Worked on Python tutorial 10 of 11, PygLatin, Ending Up! Worked on learning to slice a string.

The code used:
pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
    print original
    word = original.lower()
    first = word[0]
    new_word = word + first + pyg
    new_word = new_word[1:len(new_word)]
else:
    print 'empty'

The interaction for this code looked like this:
Enter a word: Piggy
Piggy

Saturday, July 5, 2014

Day 91

Python at CodeCademy. Worked on Python tutorial 9 of 11, PygLatin, Move it on Back! Worked on creating a new variable called "new_word" and set it equal to the concatenation of "word", "first", and "pyg".

The code used:
pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
    print original
    word = original.lower()
    first = word[0]
    new_word = word + first + pyg
else:
    print 'empty'

The interaction for this code looked like this:
Enter a word: Piggy
Piggy

Friday, July 4, 2014

Day 90

Python at CodeCademy. Worked on Python tutorial 8 of 11, PygLatin, Word Up! Worked on the ".lower()" function.

The code used:
pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
    print original
    word = original.lower()
    first = word[0]

else:
    print 'empty'

The interaction for this code looked like this:
Enter a word: Word
Word

Thursday, July 3, 2014

Day 89

Python at CodeCademy. Worked on Python tutorial 7 of 11, PygLatin, Ay B C! Worked on creating a variable to hold the translation suffix.

The code used:
pyg = "ay"

There was no interaction for this code:

Wednesday, July 2, 2014

Day 88

Python at CodeCademy. Worked on Python tutorial 6 of 11, PygLatin, Pop Quiz! Tested current code, tried some inputs that should pass and some that should fail, entered some strings that contain non-alphabetical characters and an empty string.

The code used:
print 'Welcome to the Pig Latin Translator!'

# Start coding here!
original = raw_input("Enter a word:") 

if len(original) > 0 and original.isalpha():
    print original
    
else:
    print "empty"
    

The interaction for this code looked like this:
Welcome to the Pig Latin Translator!
Enter a word: 321
empty

Welcome to the Pig Latin Translator!
Enter a word: xYz
xYz

Welcome to the Pig Latin Translator!
Enter a word: 321 xYz
empty

Tuesday, July 1, 2014

Day 87

Python at CodeCademy. Worked on Python tutorial 5 of 11, PygLatin, Check Yourself... Some More! Worked with "and" command and "isalpha()" funtion.

The code used:
print 'Welcome to the Pig Latin Translator!'

original = raw_input("Enter a word:") 

if len(original) > 0 and original.isalpha():
    print original
    
else:
    print "empty"

The interaction for this code looked like this:
Welcome to the Pig Latin Translator!
Enter a word: abc
abc

and

Welcome to the Pig Latin Translator!
Enter a word: 123
empty