Skip to content

Commit 1c434c8

Browse files
committed
Merge pull request #31 from DrAlias/master
Created code for tutorials 20, 22-24, and 28
2 parents 7b682b2 + f61033c commit 1c434c8

File tree

7 files changed

+60
-0
lines changed

7 files changed

+60
-0
lines changed

Python/20_python.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
classmates = {'Tony': ' cool but smells', 'Emma': ' sits behind me', 'Lucy': ' asks too many questions'}
2+
3+
for k, v in classmates.items():
4+
print(k + v)

Python/21_python_main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import tuna_21
2+
import random
3+
4+
tuna_21.fish()
5+
6+
x = random.randrange(1, 1000)
7+
print(x)

Python/22_python.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import random
2+
import urllib.request
3+
4+
def download_web_image(url):
5+
name = random.randrange(1, 1000)
6+
full_name = str(name) + ".jpg"
7+
urllib.request.urlretrieve(url, full_name)
8+
9+
download_web_image("https://www.thenewboston.com/images/homepage_images/main_homepage_01.png")

Python/23_python.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fw = open('sample.txt', 'w')
2+
fw.write('Writing some stuff in my text file\n')
3+
fw.write('I like bacon\n')
4+
fw.close()
5+
6+
fr = open('sample.txt', 'r')
7+
text = fr.read()
8+
print(text)
9+
fr.close()

Python/24_python.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from urllib import request
2+
3+
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
4+
5+
def download_stock_data(csv_url):
6+
response = request.urlopen(csv_url)
7+
csv = response.read()
8+
csv_str = str(csv)
9+
lines = csv_str.split("\\n")
10+
dest_url = r'goog.csv'
11+
fx = open(dest_url, "w")
12+
for line in lines:
13+
fx.write(line + "\n")
14+
fx.close()
15+
16+
download_stock_data(goog_url)

Python/28_python.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
while True:
2+
try:
3+
number = int(input("What's your fav number hoss?\n"))
4+
print(18/number)
5+
break
6+
except ValueError:
7+
print("Make sure and enter a number")
8+
except ZeroDivisionError:
9+
print("Don't pick zero")
10+
except:
11+
break
12+
finally:
13+
print("loop complete")

Python/tuna_21.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def fish():
2+
print('I am a tuna feesh!')

0 commit comments

Comments
 (0)