Skip to content

Created code for tutorials 20, 22-24, and 28 #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Python/20_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
classmates = {'Tony': ' cool but smells', 'Emma': ' sits behind me', 'Lucy': ' asks too many questions'}

for k, v in classmates.items():
print(k + v)
7 changes: 7 additions & 0 deletions Python/21_python_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import tuna_21
import random

tuna_21.fish()

x = random.randrange(1, 1000)
print(x)
9 changes: 9 additions & 0 deletions Python/22_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import random
import urllib.request

def download_web_image(url):
name = random.randrange(1, 1000)
full_name = str(name) + ".jpg"
urllib.request.urlretrieve(url, full_name)

download_web_image("https://www.thenewboston.com/images/homepage_images/main_homepage_01.png")
9 changes: 9 additions & 0 deletions Python/23_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fw = open('sample.txt', 'w')
fw.write('Writing some stuff in my text file\n')
fw.write('I like bacon\n')
fw.close()

fr = open('sample.txt', 'r')
text = fr.read()
print(text)
fr.close()
16 changes: 16 additions & 0 deletions Python/24_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from urllib import request

goog_url = http://real-chart.finance.yahoo.com/table.csv?s=GOOG&d=2&e=8&f=2015&g=d&a=2&b=27&c=2014&ignore=.csv

def download_stock_data(csv_url):
response = request.urlopen(csv_url)
csv = response.read()
csv_str = str(csv)
lines = csv_str.split("\\n")
dest_url = r'goog.csv'
fx = open(dest_url, "w")
for line in lines:
fx.write(line + "\n")
fx.close()

download_stock_data(goog_url)
13 changes: 13 additions & 0 deletions Python/28_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
while True:
try:
number = int(input("What's your fav number hoss?\n"))
print(18/number)
break
except ValueError:
print("Make sure and enter a number")
except ZeroDivisionError:
print("Don't pick zero")
except:
break
finally:
print("loop complete")
2 changes: 2 additions & 0 deletions Python/tuna_21.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def fish():
print('I am a tuna feesh!')