This file contains hidden or 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
# 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 |
This file contains hidden or 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
# 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 |
This file contains hidden or 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
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 |
This file contains hidden or 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
# 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) |
This file contains hidden or 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
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 |
This file contains hidden or 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
""" | |
Bars Module | |
============ | |
This is an example module with provide different ways to print bars. | |
""" | |
def starbar(num): | |
''' (int) -> integer | |
Prints a bar with * | |
This file contains hidden or 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
def get_length(dna): | |
""" (str) -> int | |
Return the length of the DNA sequence dna. | |
>>> get_length('ATCGAT') | |
6 | |
>>> get_length('ATCG') | |
4 | |
""" |
This file contains hidden or 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
'''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 |
This file contains hidden or 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
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 |