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
def crackle_pop(): | |
for i in range (1, 101): | |
if i % 15 == 0: | |
print("CracklePop") | |
elif i % 3 == 0: | |
print("Crackle") | |
elif i % 5 == 0: | |
print("Pop") | |
else: | |
print(i) |
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
# data from http://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/population-distribution-demography/geostat | |
# Originally seen at http://spatial.ly/2014/08/population-lines/ | |
# So, this blew up on both Reddit and Twitter. Two bugs fixed (southern Spain was a mess, | |
# and some countries where missing -- measure twice, submit once, damnit), and two silly superflous lines removed after | |
# @hadleywickham pointed that out. Also, switched from geom_segment to geom_line. | |
# The result of the code below can be seen at http://imgur.com/ob8c8ph | |
library(tidyverse) |
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
''' | |
rangoli.py | |
Design a function that prints an alphabet rangoli of size n. | |
Input: An integer n where: 0 < n < 27 | |
Output: Print the alphabet rangoli. | |
The center of the rangoli has the first alphabet letter a, | |
The boundary has the last alphabet letter indicated. | |
''' |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://d3js.org/d3.v4.min.js" charset="utf-8"></script> | |
<title>erdos d3 visualizations</title> | |
</head> | |
<body> | |
<svg class="chart"></svg> | |
<script type="text/javascript"> |
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
''' | |
rangolin.py | |
Design a function that prints an alphabet rangoli of size n. | |
Input: You are given an integer n where: 0 < n < 27 | |
Output: Print the alphabet rangoli in the format explained above. | |
The center of the rangoli has the first alphabet letter a, | |
and the boundary has the last alphabet letter indicated | |
(in alphabetical order). | |
''' |
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
# Find the sum of even-valued terms in a Fibonacci sequence | |
# the sum should not exceed 100000 | |
def even_sum(max): | |
# make Fibonacci list | |
a, b = 0, 1 | |
a, b = b, a+b | |
fib = [b] | |
# make the even-number 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
setwd("/Users/elaine.chan/Documents/Workdocs/Election/BankrateFSI/") | |
library(foreign) | |
# make new data frames by selecting columns and adding Date column | |
add_id <- function(df, filename, dirname) { | |
year <- dirname | |
month <- substr(filename, 9, 10) | |
new_df <- cbind( | |
data.frame( | |
Date=rep(as.numeric(paste(year, month, sep='')), nrow(df)) | |
), df) |
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
setwd("/Users/elaine.chan/Documents/Workdocs/Election/BankrateFSI/") | |
library(foreign) | |
# make new data frames by selecting columns and adding Date column | |
add_id <- function(df, filename, dirname) { | |
year <- dirname | |
month <- substr(filename, 9, 10) | |
new_df <- cbind( | |
data.frame( | |
Date=rep(as.numeric(paste(year, month, sep='')), nrow(df)) | |
), df) |
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
StdinNotImplementedError Traceback (most recent call last) | |
<ipython-input-22-3f40b6e2b468> in <module>() | |
1 #Find the cube root of a perfect cube | |
----> 2 x = int(input('Enter an integer: ')) | |
3 ans = 0 | |
4 while ans**3 < abs(x): | |
5 ans = ans + 1 | |
/Users/my.name/anaconda/lib/python3.5/ | |
site-packages/ipykernel/kernelbase.py in raw_input(self, prompt) |
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
x = int(input('Enter an integer: ')) | |
ans = 0 | |
while ans**3 < abs(x): | |
ans = ans + 1 | |
if ans**3 != abs(x): | |
print (x, 'is not a perfect cube') | |
else: | |
if x < 0: | |
ans = -ans | |
print ('Cube root of', x,'is', ans) |
NewerOlder