Skip to content
Open
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
22 changes: 22 additions & 0 deletions Assignments/assiagnent5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
largest = None
smallest = None
while True:
num = raw_input("Enter a number: ")
if num = "done" : break
try:
num = int(num)
except:
print "not a number"
continue
if largest is none:
largest = value
elif value > largest:
largest = value
continue
elif smallest is none:
smallest = value
elif value < smallest:
smallest = value
continue
print "Maximum", largest
print "minimum", smallest
4 changes: 4 additions & 0 deletions Assignments/assiagnent6.5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
text = "X-DSPAM-Confidence: 0.8475"
x = text.find(' ')
num = text[x+3:]
print num
20 changes: 20 additions & 0 deletions Assignments/assignment 8.4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
fname = raw_input("Enter file name: ")
if len(fname) == 0:
fname == 'romeo.txt'
try:
fh= open(fname)
except:
print "is not file"

words = []

for line in fh:
line_words= line.split()
for word in line_words:
if word in words:
continue
word.appened(word)

print sorted(words)


20 changes: 20 additions & 0 deletions Assignments/assignment10.2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name = raw_input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"

try:
handle= open(name)
except:
print "is not file"

hours = {}

for line in handle:
if not line.startswith('from '):
continue
hours = line.split()
time = hours [5]
hour = time.split(:)
hours[hour[0]] = hours.get(hour[0], 1) + 1

print "\nHours & Counts"
print hours
6 changes: 6 additions & 0 deletions Assignments/assignment11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import re
numlst=[]
num=re.findall('[0-9]+',http://python-data.dr-chuck.net/regex_sum_242232.txt.read())
numlst.appened(num)
numlst = int(num)
print sum(numlst)
15 changes: 15 additions & 0 deletions Assignments/assignment12.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import socket

socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

socket.connect(("www.pythonlearn.com",80))

socket.send("GET http://www.pythonlearn.com/code/intro-short.txt HTTP/1.0\n\n")

while True:
data = socket.recv(512)
if (len(data) < 1):
break
print data

socket.close()
7 changes: 7 additions & 0 deletions Assignments/assignment13.1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import urllib
from BeautifulSoup import *
num = []
for tag in BeautifulSoup(urllib.urlopen('http://python-data.dr-chuck.net/comments_242237.html').read())('span'):
num.append(tag.contents[0])
int(num)
print sum(num)
21 changes: 21 additions & 0 deletions Assignments/assignment13.2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import urllib
from BeautifulSoup import *

url = raw_input(" URL: ")
count = raw_input(" count: ")
position = raw_input(" position: ")

count = int(count)
position = int(position)

while count > 0:
links = []
tags = BeautifulSoup(urllib.urlopen(url).read())('a')

for tag in tags:
links.append(tag.get('href', None))

url = links[position-1]
count -= 1

print url
10 changes: 10 additions & 0 deletions Assignments/assignment14.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import urllib
import xml.etree.ElementTree as ET

while True:
url = raw_input("Enter URL: ")
if len(url) < 1 : break
total = 0
for comment in ET.fromstring(urllib.urlopen(url).read()).findall('comments/comment'):
total += int(comment.find('count').text)
print total
15 changes: 15 additions & 0 deletions Assignments/assignment15.1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import urllib
import json

while True:
url = raw_input('\nEnter location: ')
if len(url) < 1 : break

print 'Retrieving', url
print '\nRetrieved',len(urllib.urlopen(url).read()),'characters'
print 'Count:', len(json.loads(urllib.urlopen(url).read())['comments'])

total = 0
for num in json.loads(urllib.urlopen(url).read())['comments']:
total += int(num['count'])
print 'Sum:', total
17 changes: 17 additions & 0 deletions Assignments/assignment15.2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import urllib
import json

url = raw_input('Enter URL: ')

uh = urllib.urlopen(url).read()

info = json.loads(uh)

lst = list()

for num in info['comments']:
lst.append(int(num['count']))

total = sum(lst)

print 'Sum: ', total
12 changes: 12 additions & 0 deletions Assignments/assignment2_Michael.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
hours = raw_input ("enter hours:")
pay = raw_input("Enter pay rate:")

total = float(hours) * float(pay)

#hereis the amount I owe
#
#
#
#
#
print "hey I owe you", total
17 changes: 17 additions & 0 deletions Assignments/assignment4.6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def compute_pay(rate, hours):
try:
rate = float(rate)
hours = float(hours)
except:
print "these need to be numbers"
if hours > 40:
extra_hours = hours - 40
extra_pay = rate * 1.5
total = (rate * 40)+ (extra_pay * extra_hours)
return total
else:
total = rate* hours
return total

p = Compute_pay( 10,20 )
print p
5 changes: 5 additions & 0 deletions Assignments/assignment7.1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fname = raw_input("Enter file name: ")
fh = open(fname)

for line in fh:
print line.upper()
20 changes: 20 additions & 0 deletions Assignments/assignment7.4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
fname = raw_input("Enter file name: ")

if len(fname) == 0:
fname == 'mbox-short.txt'

try:
fh= open(fname)
except:
print "is not file"

for line in fh:
if not line.startswith('X-DSPAM-Confidence: 0.8475'):
continue

num_start = line.find('0')
num = line[num_start]
flt = float(num)
count += flt

print count
21 changes: 21 additions & 0 deletions Assignments/assignment8.5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
fname = raw_input("Enter file name: ")

if len(fname) == 0:
fname == 'mbox-short.txt'

try:
fh= open(fname)
except:
print "is not file"

count = 0

for line in fh:
if not line.startswith('from '):
continue
words_list = line.split()
email = words_list[1]
count += 1
print email

print count
29 changes: 29 additions & 0 deletions Assignments/assignment9.4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name = raw_input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"

try:
handle= open(name)
except:
print "is not file"

emails = {}
email_list =[]

for line in handle:
if not line.startswith('from '):
continue
email_list = line.split()
email = words[1]
email_list.appened(email)

for adress in email_list:
email[adress] = emails.get(adress,0)+1

big_adress = None
big_number = None

for adress,count in emails.item():
if big_count is None or count > big_count:
big_count = count
big_adress= adress
print big_adress,big_count
2 changes: 2 additions & 0 deletions Assignments/assignment_Michael.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x="Wello World"
print x
14 changes: 14 additions & 0 deletions Assignments/calc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
hours = raw_input ("Enter Hours: ")
rate = raw_input ("Enter Rate: ")
h = float(hours)
r = float(rate)
if h > 40:
overtimeRate = 1.5 * r
overtime = (h-40) * overtimeRate
h = 40
pay = h * r + overtime
print pay
else:
overtime = 0
pay = h * r + overtime
print pay
20 changes: 20 additions & 0 deletions Assignments/grade.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
score = raw_input("Enter Score: ")
s= float(score)
def grade(s):
if s >= 0.9:
return 'A'
elif s >= 0.8:
return 'B'
elif s >= 0.7:
return 'C'
elif s >= 0.6:
return 'D'
elif s < 0.6:
return 'F'
elif s > 1.0:
return 'error'
elif s < 0.0:
return 'error'
else:
return "no score"
print grade(s)