Skip to content

Instantly share code, notes, and snippets.

@lucpet
lucpet / Question6.py
Created October 18, 2013 10:13
Question 6
def future_value(present_value, annual_rate, periods_per_year, years):
'''
>>> future_value(500, .04, 10, 10)
745.317442824
'''
rate_per_period = annual_rate / periods_per_year
periods = periods_per_year * years
future_value = present_value * (1 + rate_per_period) ** periods
return future_value
@lucpet
lucpet / a3.py
Created September 28, 2013 12:11
Assignment 3
'''A board is a list of list of str. For example, the board
ANTT
XSOB
is represented as the list
[['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']]
A word list is a list of str. For example, the list of words
ANT
BOX
SOB
@lucpet
lucpet / a2.py
Last active December 22, 2015 23:19
My answers to Assignment 2
def get_length(dna):
""" (str) -> int
Return the length of the DNA sequence dna.
>>> get_length('ATCGAT')
6
>>> get_length('ATCG')
4
"""
@lucpet
lucpet / bars.py
Last active December 22, 2015 13:58
Bars Module ============ This is an example module with provide different ways to print bars.
"""
Bars Module
============
This is an example module with provide different ways to print bars.
"""
def starbar(num):
''' (int) -> integer
Prints a bar with *
@lucpet
lucpet / shit_happens.py
Last active December 22, 2015 07:09
Example if elif else statement
if 2 + 2 >= 5: # if shit happens do shit
print('woo hoo')
elif 2 + 2 >= 4: # if that last shit didn't happen then do this
print('yay')
else:
2 + 2 <= 3 # if none of that last shit happened then do this
print('WTF')
#----------------------------------------------------------------
def stuff_happens(num):
if 2 + num >= 5: # if stuff happens do shit
@lucpet
lucpet / a1.py
Created September 4, 2013 11:19
Learn to Program Assignment 1
# step 2
def seconds_difference(time_1, time_2):
""" (number, number) -> number
Return the number of seconds later that a time in seconds
time_2 is than a time in seconds time_1.
>>> seconds_difference(1800.0, 3600.0)
1800.0
>>> seconds_difference(3600.0, 1800.0)
@lucpet
lucpet / Poly_Area
Last active December 21, 2015 23:39
Answer to the fundamentals facebook challenge
import math
def poly_area(n_sides, side_len):
''' (number, number) -> number
Calculates the area of a Polygon
using the length of one side
poly_area(7, 3)
>>> 32.705
@lucpet
lucpet / Practical Python Chapter 3 exercises
Last active September 11, 2020 01:37
Practical Python Chapter 3 exercises
# 3. Following the function design recipe, define a function that has one
# parameter, a number, and returns that number tripled.
def recipie(x):
""" (number) -> number
Following the function design recipe, define a function that has one
parameter, a number, and returns that number tripled.
"""
return x * 3
# 1. Write a function that takes two number parameters and
# returns their product
def mult_me(x, y):
z = x * y
return z
mult_me(123, -2)
#-----------------------------------------------------------
# 2. Write a function that takes two string parameters and
# returns a string that is a concatenation of the second