diff --git a/Assignments/assiagnent5.py b/Assignments/assiagnent5.py new file mode 100644 index 0000000..0758582 --- /dev/null +++ b/Assignments/assiagnent5.py @@ -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 \ No newline at end of file diff --git a/Assignments/assiagnent6.5.py b/Assignments/assiagnent6.5.py new file mode 100644 index 0000000..f82b884 --- /dev/null +++ b/Assignments/assiagnent6.5.py @@ -0,0 +1,4 @@ +text = "X-DSPAM-Confidence: 0.8475" +x = text.find(' ') +num = text[x+3:] +print num \ No newline at end of file diff --git a/Assignments/assignment 8.4.py b/Assignments/assignment 8.4.py new file mode 100644 index 0000000..f9fe9a8 --- /dev/null +++ b/Assignments/assignment 8.4.py @@ -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) + + \ No newline at end of file diff --git a/Assignments/assignment10.2.py b/Assignments/assignment10.2.py new file mode 100644 index 0000000..3246196 --- /dev/null +++ b/Assignments/assignment10.2.py @@ -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 \ No newline at end of file diff --git a/Assignments/assignment11.py b/Assignments/assignment11.py new file mode 100644 index 0000000..cad9942 --- /dev/null +++ b/Assignments/assignment11.py @@ -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) \ No newline at end of file diff --git a/Assignments/assignment12.py b/Assignments/assignment12.py new file mode 100644 index 0000000..96d14d8 --- /dev/null +++ b/Assignments/assignment12.py @@ -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() \ No newline at end of file diff --git a/Assignments/assignment13.1.py b/Assignments/assignment13.1.py new file mode 100644 index 0000000..13638f5 --- /dev/null +++ b/Assignments/assignment13.1.py @@ -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) \ No newline at end of file diff --git a/Assignments/assignment13.2.py b/Assignments/assignment13.2.py new file mode 100644 index 0000000..8ea3147 --- /dev/null +++ b/Assignments/assignment13.2.py @@ -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 diff --git a/Assignments/assignment14.py b/Assignments/assignment14.py new file mode 100644 index 0000000..bc0c6ee --- /dev/null +++ b/Assignments/assignment14.py @@ -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 \ No newline at end of file diff --git a/Assignments/assignment15.1.py b/Assignments/assignment15.1.py new file mode 100644 index 0000000..396a9c7 --- /dev/null +++ b/Assignments/assignment15.1.py @@ -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 \ No newline at end of file diff --git a/Assignments/assignment15.2.py b/Assignments/assignment15.2.py new file mode 100644 index 0000000..64040c0 --- /dev/null +++ b/Assignments/assignment15.2.py @@ -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 diff --git a/Assignments/assignment2_Michael.py b/Assignments/assignment2_Michael.py new file mode 100644 index 0000000..21281a3 --- /dev/null +++ b/Assignments/assignment2_Michael.py @@ -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 \ No newline at end of file diff --git a/Assignments/assignment4.6.py b/Assignments/assignment4.6.py new file mode 100644 index 0000000..f1148d6 --- /dev/null +++ b/Assignments/assignment4.6.py @@ -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 \ No newline at end of file diff --git a/Assignments/assignment7.1.py b/Assignments/assignment7.1.py new file mode 100644 index 0000000..46ff0ec --- /dev/null +++ b/Assignments/assignment7.1.py @@ -0,0 +1,5 @@ +fname = raw_input("Enter file name: ") +fh = open(fname) + +for line in fh: + print line.upper() \ No newline at end of file diff --git a/Assignments/assignment7.4.py b/Assignments/assignment7.4.py new file mode 100644 index 0000000..895999e --- /dev/null +++ b/Assignments/assignment7.4.py @@ -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 \ No newline at end of file diff --git a/Assignments/assignment8.5.py b/Assignments/assignment8.5.py new file mode 100644 index 0000000..c3ed6ea --- /dev/null +++ b/Assignments/assignment8.5.py @@ -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 diff --git a/Assignments/assignment9.4.py b/Assignments/assignment9.4.py new file mode 100644 index 0000000..95838d6 --- /dev/null +++ b/Assignments/assignment9.4.py @@ -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 \ No newline at end of file diff --git a/Assignments/assignment_Michael.py b/Assignments/assignment_Michael.py new file mode 100644 index 0000000..a6210c7 --- /dev/null +++ b/Assignments/assignment_Michael.py @@ -0,0 +1,2 @@ +x="Wello World" +print x \ No newline at end of file diff --git a/Assignments/calc.py b/Assignments/calc.py new file mode 100644 index 0000000..7152460 --- /dev/null +++ b/Assignments/calc.py @@ -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 \ No newline at end of file diff --git a/Assignments/grade.py b/Assignments/grade.py new file mode 100644 index 0000000..f8a5542 --- /dev/null +++ b/Assignments/grade.py @@ -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) \ No newline at end of file