From deca90ee646097ce338479981a611c4420ddefe0 Mon Sep 17 00:00:00 2001 From: Guessan Date: Tue, 29 Mar 2016 20:35:44 -0400 Subject: [PATCH 1/6] assignment 1 --- Assignments/Assignment1_GuessanEffi.py | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Assignments/Assignment1_GuessanEffi.py diff --git a/Assignments/Assignment1_GuessanEffi.py b/Assignments/Assignment1_GuessanEffi.py new file mode 100644 index 0000000..fc3b143 --- /dev/null +++ b/Assignments/Assignment1_GuessanEffi.py @@ -0,0 +1,2 @@ +x = "hello world" +print x From 715cabbdeefa57a0c2c3e2f1bd7d60439c6ac0e2 Mon Sep 17 00:00:00 2001 From: Guessan Date: Tue, 5 Apr 2016 19:57:55 -0400 Subject: [PATCH 2/6] assignments1-3 --- Assignments/Assignment1_GuessanEffi.py | 2 ++ Assignments/Pay Role Code.py | 5 +++++ Assignments/PayCode.py | 5 +++++ 3 files changed, 12 insertions(+) create mode 100644 Assignments/Pay Role Code.py create mode 100644 Assignments/PayCode.py diff --git a/Assignments/Assignment1_GuessanEffi.py b/Assignments/Assignment1_GuessanEffi.py index fc3b143..da32497 100644 --- a/Assignments/Assignment1_GuessanEffi.py +++ b/Assignments/Assignment1_GuessanEffi.py @@ -1,2 +1,4 @@ x = "hello world" print x + +print "hello world" diff --git a/Assignments/Pay Role Code.py b/Assignments/Pay Role Code.py new file mode 100644 index 0000000..84d46ac --- /dev/null +++ b/Assignments/Pay Role Code.py @@ -0,0 +1,5 @@ +#Pay Role Code +hours = raw_input('Enter Hours: ') +pay = raw_input('Enter Pay Rate: ') +total = float(hours) * float(pay) +print "Hey I Owe You", total \ No newline at end of file diff --git a/Assignments/PayCode.py b/Assignments/PayCode.py new file mode 100644 index 0000000..84d46ac --- /dev/null +++ b/Assignments/PayCode.py @@ -0,0 +1,5 @@ +#Pay Role Code +hours = raw_input('Enter Hours: ') +pay = raw_input('Enter Pay Rate: ') +total = float(hours) * float(pay) +print "Hey I Owe You", total \ No newline at end of file From 327ac510a63dd5b9701c387fbcbdadefc971fd7b Mon Sep 17 00:00:00 2001 From: Guessan Date: Tue, 12 Apr 2016 20:30:34 -0400 Subject: [PATCH 3/6] Uploaded New Files and Notes --- Assignments/Blastoff.py | 4 +++ Assignments/Class_notes.py | 7 +++++ Assignments/Class_notes2.py | 6 ++++ Assignments/Largest | 7 +++++ Assignments/Largest.py | 18 +++++++++++ Assignments/Notes 4_7_16.py | 21 +++++++++++++ Assignments/Notes4_7_16.py | 62 +++++++++++++++++++++++++++++++++++++ 7 files changed, 125 insertions(+) create mode 100644 Assignments/Blastoff.py create mode 100644 Assignments/Class_notes.py create mode 100644 Assignments/Class_notes2.py create mode 100644 Assignments/Largest create mode 100644 Assignments/Largest.py create mode 100644 Assignments/Notes 4_7_16.py create mode 100644 Assignments/Notes4_7_16.py diff --git a/Assignments/Blastoff.py b/Assignments/Blastoff.py new file mode 100644 index 0000000..bc84cd8 --- /dev/null +++ b/Assignments/Blastoff.py @@ -0,0 +1,4 @@ + +for i in [5, 4, 3, 2, 1] : + print i +print "Blastoff!!!" diff --git a/Assignments/Class_notes.py b/Assignments/Class_notes.py new file mode 100644 index 0000000..a93d892 --- /dev/null +++ b/Assignments/Class_notes.py @@ -0,0 +1,7 @@ +while True: + line = raw_input ('Write: ') + if line == 'Done': + break + print line +print 'Duh-Done-Done' + diff --git a/Assignments/Class_notes2.py b/Assignments/Class_notes2.py new file mode 100644 index 0000000..0111c19 --- /dev/null +++ b/Assignments/Class_notes2.py @@ -0,0 +1,6 @@ +while True: + line = raw_input ('Write: ') + if line == 'Done' + break + print line +print 'Duh-Done-Done' diff --git a/Assignments/Largest b/Assignments/Largest new file mode 100644 index 0000000..e19c5af --- /dev/null +++ b/Assignments/Largest @@ -0,0 +1,7 @@ +largest_num = 10 +print "Before" , largest_num +for num_ in [9, 15, 24, 32, 41, 41, 100, 53, 82, 1000] : + if num_ > largest_num : + largest_num = num_ + print largest_num, num_ +print "After", largest_num \ No newline at end of file diff --git a/Assignments/Largest.py b/Assignments/Largest.py new file mode 100644 index 0000000..96fc995 --- /dev/null +++ b/Assignments/Largest.py @@ -0,0 +1,18 @@ +largest_num = 10 +#print "Before" , largest_num +#for num_ in [9, 15, 24, 32, 41, 41, 100, 53, 82, 1000] : +# if num_ > largest_num : +# largest_num = num_ +# print largest_num, num_ +#print "After", largest_num + +print "Before" +for value in [91, 20, 34, 3945, 764, 3, 1, 13] : + if value > None: + Largest_Number = value + print Largest_Number + if Largest_Number > #than the last value +#find out how to create an array from the printed +#answers then figure out how to sort throught that arry + +#Que tu tienes? Qu'est-ce que tu veut? \ No newline at end of file diff --git a/Assignments/Notes 4_7_16.py b/Assignments/Notes 4_7_16.py new file mode 100644 index 0000000..e5d6107 --- /dev/null +++ b/Assignments/Notes 4_7_16.py @@ -0,0 +1,21 @@ +#Notes 7/4/16 + +#Using the def assignment to create a neew function, whenever you want a short cut +#Example: + +def greeting(): + print 'Hello' + +greeting() +greeting() +greeting() +greeting() +greeting() + +def addOne(num): + numPlus = num + 1 + print numPlus + +addOne(1) +addOne(3) +addOne(1000) \ No newline at end of file diff --git a/Assignments/Notes4_7_16.py b/Assignments/Notes4_7_16.py new file mode 100644 index 0000000..959094c --- /dev/null +++ b/Assignments/Notes4_7_16.py @@ -0,0 +1,62 @@ +#Notes 7/4/16 + +#Using the def assignment to create a neew function, whenever you want a short cut +#Example: + +def greeting(): + print 'Hello' + +greeting() +greeting() +greeting() +greeting() +greeting() + +def addOne(num): + numPlus = num * 2 + print numPlus + +addOne(1) +addOne(3) +addOne(1000) + +def home(): + print 'This my house!' + +home() + +def delt(): + print 'Who smelt it, delt...' + +delt() + +def pay_calc(h, r): + pay = h*r + print pay + +hours = float(raw_input('Hours:')) +rate = 13.50 + +pay_calc(hours,rate) + + +letter = max('Guessan') +print letter + +def name(my, your): + print "my friend is", my , "your firend is", your + +name("bob", "lisa") + +#srrr = "lisa" +#name("bob", srrr) +#You can create several place holder within your code, as long as you finalize and declare your variables + +#RETURN +def two_plus(): + number = 2 + 325652 + return number +#not print bc you want to do other stuff with your defined function + +eight = two_plus() * 2 +print eight From de188f9637e3452fcc0837f548ed9cd1e57a3cc1 Mon Sep 17 00:00:00 2001 From: Guessan Date: Thu, 14 Apr 2016 17:47:30 -0400 Subject: [PATCH 4/6] Assignment 3.1 --- Assignments/Answer_3.1 | 7 +++++++ Assignments/Answer_3.1.py | 13 +++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 Assignments/Answer_3.1 create mode 100644 Assignments/Answer_3.1.py diff --git a/Assignments/Answer_3.1 b/Assignments/Answer_3.1 new file mode 100644 index 0000000..018f90c --- /dev/null +++ b/Assignments/Answer_3.1 @@ -0,0 +1,7 @@ +hours = raw_input('Enter Hours: ') + return hours + if hours >= 41 + hours = 1.5 * hours +pay = raw_input('Enter Pay Rate: ') +total = float(hours) * float(pay) +print "Your Gross Pay is: ", total diff --git a/Assignments/Answer_3.1.py b/Assignments/Answer_3.1.py new file mode 100644 index 0000000..192e14e --- /dev/null +++ b/Assignments/Answer_3.1.py @@ -0,0 +1,13 @@ +hours = raw_input('Enter Hours: ') +hours = float(hours) +rate = raw_input('Enter Pay Rate: ') +rate = float(rate) +if hours > 40.0: +#The first 40 hours should be the normal rate, and after 40 hours +#The rate should be 1.5 +#41 , 40 x rate + (41-40) x 1.5 x rate + total = (40 * rate) + ((rate*1.5) * (hours-40)) +elif hours <= 40.0: + total = hours * rate + +print "Your Gross Pay is: ", total From a576fd6cc2d91c0425045462b9c4de436186d263 Mon Sep 17 00:00:00 2001 From: Guessan Date: Tue, 17 May 2016 17:22:57 -0400 Subject: [PATCH 5/6] Assignments --- Assignments/Answer_3.3.py | 32 +++++++ Assignments/Answer_4.6.py | 19 +++++ Assignments/Answer_4.6_8.5 | 115 +++++++++++++++++++++++++ Assignments/Answer_4.6_8.5.py | 155 ++++++++++++++++++++++++++++++++++ Assignments/Answer_5.2.py | 30 +++++++ Assignments/Answer_6.5.py | 13 +++ Assignments/Answer_7.1.py | 12 +++ Assignments/Answer_7.3.py | 30 +++++++ Assignments/Answer_8.4.py | 17 ++++ Assignments/Answer_8.5.py | 18 ++++ Assignments/Class_Notes_21.py | 31 +++++++ Assignments/Class_notes14.py | 43 ++++++++++ Assignments/Class_notes_!2.py | 0 13 files changed, 515 insertions(+) create mode 100644 Assignments/Answer_3.3.py create mode 100644 Assignments/Answer_4.6.py create mode 100644 Assignments/Answer_4.6_8.5 create mode 100644 Assignments/Answer_4.6_8.5.py create mode 100644 Assignments/Answer_5.2.py create mode 100644 Assignments/Answer_6.5.py create mode 100644 Assignments/Answer_7.1.py create mode 100644 Assignments/Answer_7.3.py create mode 100644 Assignments/Answer_8.4.py create mode 100644 Assignments/Answer_8.5.py create mode 100644 Assignments/Class_Notes_21.py create mode 100644 Assignments/Class_notes14.py create mode 100644 Assignments/Class_notes_!2.py diff --git a/Assignments/Answer_3.3.py b/Assignments/Answer_3.3.py new file mode 100644 index 0000000..ab46924 --- /dev/null +++ b/Assignments/Answer_3.3.py @@ -0,0 +1,32 @@ +#Assignment: Write a program to prompt for a score between 0.0 and 1.0. +#If the score is out of range, print an error. If the score is between 0.0 and 1.0, print a grade using the following table: + +#Score Grade +#>= 0.9 A +#>= 0.8 B +#>= 0.7 C +#>= 0.6 D +#< 0.6 F + +#If the user enters a value out of range, print a suitable error message and exit. For the test, enter a score of 0.85. + +#Please begin writing the program with the code below: +#score = raw_input("Enter Score: ") + +score = raw_input("Enter your score: ") + #if type(raw_input) == string + #print "ERROR: Please enter a number score." + #score = raw_input("Enter your score: ") +elif score <= 0.9: + print "Your grade is an A" +elif score >= 0.8: + print "Your grade is a B" +elif score >= 0.7: + print "Your grade is a C" +elif score >= 0.6: + print "Your grade is a D" +elif score < 0.6: + print "Your grade is a F" +if score > 1: + print "Please enter a score within the range of 0.0 to 1.0" + raw_input("Enter your score: ") \ No newline at end of file diff --git a/Assignments/Answer_4.6.py b/Assignments/Answer_4.6.py new file mode 100644 index 0000000..41a4a01 --- /dev/null +++ b/Assignments/Answer_4.6.py @@ -0,0 +1,19 @@ +#4.6 +#raw_input hours and rate per hours to compute gross pay. Change to float +#Award time-and-a-half for the hourly rate for all hrs worked above 40h +#Put the logic to compute time 1/2 pay as function computepay() and use +#float() to convert the #string to a number. +#Do not use sum() + +hours = raw_input("Enter worked hours: ") +hours = float(hours) +rate = raw_input("Enter hourly rate: ") +rate = float(rate) +def computepay(): + return (40 * rate) + ((rate*1.5) * (hours-40)) +if hours > 40.0: + computepay() + print "Your Gross Pay is: ", computepay() +elif hours <= 40.0: + total = hours * rate + print "Your Gross Pay is: ", total \ No newline at end of file diff --git a/Assignments/Answer_4.6_8.5 b/Assignments/Answer_4.6_8.5 new file mode 100644 index 0000000..090e000 --- /dev/null +++ b/Assignments/Answer_4.6_8.5 @@ -0,0 +1,115 @@ +#4.6 +#raw_input hours and rate per hours to compute gross pay. Change to float +#Award time-and-a-half for the hourly rate for all hrs worked above 40h +#Put the logic to compute time 1/2 pay as function computepay() and use +float() to convert the #string to a number. +#Do not use sum() + +#Begin writing the program with the code below: +#def computepay(h,r): + # return 42.37 + +#hrs = raw_input("Enter Hours:") +#p = computepay(10,20) +#print "Pay",p + + + + +#5.2 +#Write a program that repeatedly prompts a user for integer numbers #until the user enters 'done'. +#Once 'done' is entered, print out the largest and smallest of the #numbers. +#If the user enters anything other than a valid number catch it with a #try/except and put out an appropriate message and ignore #the number. + + +#Begin writing the program with the code below: +#largest = None +#smallest = None +#while True: + # num = raw_input("Enter a number: ") + # if num == "done" : break + # print num + +#print "Maximum", largest + + + + +#6.5 +#Write code using find() and string slicing (see section 6.10) to #extract the number at the end of the line below. +#Convert the extracted value to a floating point number and print it #out. + +#Please use the line below: +#text = "X-DSPAM-Confidence: 0.8475"; + + + + +#7.1 +#Write a program that prompts for a file name, then opens #that file and reads through the file, +#and print the contents of the file in upper case. +#Use the file words.txt to produce the output below. + +#You can download the sample data at http://www.pythonlearn.com/code/words.txt + +#Begin to write the program with the following code below: +# Use words.txt as the file name +#fname = raw_input("Enter file name: ") +#fh = open(fname) + + + + +#7.3 +#Write a program that prompts for a file name, then opens #that file and reads through the file, looking for lines of #the form: +#X-DSPAM-Confidence: 0.8475 + +#Count these lines and extract the floating point values #from each of the lines and compute +#the average of those values and produce an output as shown #below. +#Do not use the sum() function or a variable named sum in #your solution. + +#You can download the sample data at http://www.pythonlearn.com/code/mbox-short.txt +#when you are testing below enter mbox-short.txt as the #file name. + + + + + +#8.4 +#Open the file romeo.txt and read it line by line. For each line, split the line into a list of words using the split() method. +#The program should build a list of words. +#For each word on each line check to see if the word is already in the list and if not append it to the list. +#When the program completes, sort and print the resulting words in alphabetical order. + +#You can download the sample data at http://www.pythonlearn.com/code/romeo.txt + + +#Begin to write the program with the following code below: +#fname = raw_input("Enter file name: ") +#fh = open(fname) +#lst = list() +#for line in fh: +#print line.rstrip() + + + + + +#8.5 +#Open the file mbox-short.txt and read it line by line. When you find a line that starts with 'From ' like the following line: +#From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008 + +#You will parse the From line using split() and print out the second word in the line (i.e. the entire address of the person +#who sent the message). Then print out a count at the end. +#Hint: make sure not to include the lines that start with 'From:'. + +#You can download the sample data at http://www.pythonlearn.com/code/mbox-short.txt + + +#Begin to write the program with the following code below: +#fname = raw_input("Enter file name: ") +#if len(fname) < 1 : fname = "mbox-short.txt" + +#fh = open(fname) +#count = 0 + diff --git a/Assignments/Answer_4.6_8.5.py b/Assignments/Answer_4.6_8.5.py new file mode 100644 index 0000000..48add5f --- /dev/null +++ b/Assignments/Answer_4.6_8.5.py @@ -0,0 +1,155 @@ +#4.6 +#raw_input hours and rate per hours to compute gross pay. Change to float +#Award time-and-a-half for the hourly rate for all hrs worked above 40h +#Put the logic to compute time 1/2 pay as function computepay() and use +#float() to convert the #string to a number. +#Do not use sum() + +hours = raw_input("Enter worked hours: ") +hours = float(hours) +rate = raw_input("Enter hourly rate: ") +rate = float(rate) +def computepay(): + return (40 * rate) + ((rate*1.5) * (hours-40)) +if hours > 40.0: + computepay() + print "Your Gross Pay is: ", computepay() +elif hours <= 40.0: + total = hours * rate + print "Your Gross Pay is: ", total + + + +#5.2 +#Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. +#Once 'done' is entered, print out the largest and smallest of the #numbers. +#If the user enters anything other than a valid number catch it with a #try/except and put out an appropriate message and ignore #the number. + +largest = None +smallest = None +while True: + num = raw_input("Enter a number: ") + if num == "done" : break + print num + try: + num = float(num) + + except: + return "Please Enter a Number" + continue +l = list() +#l.insert(num) +l.append(num) + for num in l : + if num > largest : + largest = num + #print "This is the largest number: ", largest + elif num < smallest : + smallest = num + #print "This is the smallest number: ", smallest +print "Max: ", largest +print "Min: ", small + + +#6.5 +#Write code using find() and string slicing (see section 6.10) to extract the number at the end of the line below. +#Convert the extracted value to a floating point number and print it out. + +#Please use the line below: +text = "X-DSPAM-Confidence: 0.8475"; +text_num = text.find('0') +new_num = [text_num:] +continue +print new_num + #how can I assign this to the variable new_num? + #new_num = float(new_num) + #print new_num + + + +#7.1 +#Write a program that prompts for a file name, then opens #that file and reads through the file, +#and print the contents of the file in upper case. +#Use the file words.txt to produce the output below. + +#You can download the sample data at http://www.pythonlearn.com/code/words.txt + +#Begin to write the program with the following code below: +# Use words.txt as the file name +fname = raw_input("Enter file name: ") +fhand = open(fname) +print fhand.upper() + + + +#7.3 +#Write a program that prompts for a file name, then opens #that file and reads through the file, looking for lines of the form: +#X-DSPAM-Confidence: 0.8475 +#Count these lines and extract the floating point values from each of the lines and compute +#the average of those values and produce an output as shown #below. +#Do not use the sum() function or a variable named sum in #your solution. + +#You can download the sample data at http://www.pythonlearn.com/code/mbox-short.txt +#when you are testing below enter mbox-short.txt as the #file name. + +fname = raw_input("Enter file name: ") +fh = open(fname) +file = fh.read() +count = 0 +for line in file : + if line.startswith ('X-DSPAM-Confidence: 0.8475'): + line = line.rstrip() + print line + #How do I assign the new lines as a new file + newfile = line + count = count + 1 + print 'Count: ', count + #How do I extract the int + for newline in newfile : + print newfile.find('0') + #How do I grab those strings, then change them into floats, then sum them up + #k = list () + #newfile.append(k) + #print len(k) + #k[0:to the end] and then add them? + + + +#8.4 +#Open the file romeo.txt and read it line by line. For each line, split the line into a list of words using the split() method. +#The program should build a list of words. +#For each word on each line check to see if the word is already in the list and if not append it to the list. +#When the program completes, sort and print the resulting words in alphabetical order. + +#You can download the sample data at http://www.pythonlearn.com/code/romeo.txt + + +#Begin to write the program with the following code below: +fname = raw_input("Enter file name: ") +fh = open(fname) +fh = fh.split() +lst = list() +fh.append(lst) +for wrd in lst : + print wrd.rstrip() + + + +#8.5 +#Open the file mbox-short.txt and read it line by line. When you find a line that starts with 'From ' like the following line: +#From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008 + +#You will parse the From line using split() and print out the second word in the line (i.e. the entire address of the person +#who sent the message). Then print out a count at the end. +#Hint: make sure not to include the lines that start with 'From:'. + +#You can download the sample data at http://www.pythonlearn.com/code/mbox-short.txt + + +#Begin to write the program with the following code below: +#fname = raw_input("Enter file name: ") +#if len(fname) < 1 : fname = "mbox-short.txt" + +#fh = open(fname) +#count = 0 + diff --git a/Assignments/Answer_5.2.py b/Assignments/Answer_5.2.py new file mode 100644 index 0000000..de16129 --- /dev/null +++ b/Assignments/Answer_5.2.py @@ -0,0 +1,30 @@ +#5.2 +#Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. +#Once 'done' is entered, print out the largest and smallest of the #numbers. +#If the user enters anything other than a valid number catch it with a #try/except and put out an appropriate message and ignore #the number. + +largest = None +smallest = None +while True: + num = raw_input("Enter a number: ") + if num == "done" : break + print num + try: + num = float(num) + + except: + return "Please Enter a Number" + continue +l = list() +#l.insert(num) +l.append(num) + for num in l : + if num > largest : + largest = num + #print "This is the largest number: ", largest + elif num < smallest : + smallest = num + #print "This is the smallest number: ", smallest +print "Max: ", largest +print "Min: ", small + diff --git a/Assignments/Answer_6.5.py b/Assignments/Answer_6.5.py new file mode 100644 index 0000000..cd54eb5 --- /dev/null +++ b/Assignments/Answer_6.5.py @@ -0,0 +1,13 @@ +#6.5 +#Write code using find() and string slicing (see section 6.10) to extract the number at the end of the line below. +#Convert the extracted value to a floating point number and print it out. + +#Please use the line below: +text = "X-DSPAM-Confidence: 0.8475"; +text_num = text.find('0') +new_num = [text_num:] +continue +print new_num + #how can I assign this to the variable new_num? + #new_num = float(new_num) + #print new_num diff --git a/Assignments/Answer_7.1.py b/Assignments/Answer_7.1.py new file mode 100644 index 0000000..d96a8bf --- /dev/null +++ b/Assignments/Answer_7.1.py @@ -0,0 +1,12 @@ +#7.1 +#Write a program that prompts for a file name, then opens #that file and reads through the file, +#and print the contents of the file in upper case. +#Use the file words.txt to produce the output below. + +#You can download the sample data at http://www.pythonlearn.com/code/words.txt + +#Begin to write the program with the following code below: +# Use words.txt as the file name +fname = raw_input("Enter file name: ") +fhand = open(fname) +print fhand.upper() \ No newline at end of file diff --git a/Assignments/Answer_7.3.py b/Assignments/Answer_7.3.py new file mode 100644 index 0000000..1aa579c --- /dev/null +++ b/Assignments/Answer_7.3.py @@ -0,0 +1,30 @@ +#7.3 +#Write a program that prompts for a file name, then opens #that file and reads through the file, looking for lines of the form: +#X-DSPAM-Confidence: 0.8475 +#Count these lines and extract the floating point values from each of the lines and compute +#the average of those values and produce an output as shown #below. +#Do not use the sum() function or a variable named sum in #your solution. + +#You can download the sample data at http://www.pythonlearn.com/code/mbox-short.txt +#when you are testing below enter mbox-short.txt as the #file name. + +fname = raw_input("Enter file name: ") +fh = open(fname) +file = fh.read() +count = 0 +for line in file : + if line.startswith ('X-DSPAM-Confidence: 0.8475'): + line = line.rstrip() + print line + #How do I assign the new lines as a new file + newfile = line + count = count + 1 + print 'Count: ', count + #How do I extract the int + for newline in newfile : + print newfile.find('0') + #How do I grab those strings, then change them into floats, then sum them up + #k = list () + #newfile.append(k) + #print len(k) + #k[0:to the end] and then add them? diff --git a/Assignments/Answer_8.4.py b/Assignments/Answer_8.4.py new file mode 100644 index 0000000..0a9b905 --- /dev/null +++ b/Assignments/Answer_8.4.py @@ -0,0 +1,17 @@ +#8.4 +#Open the file romeo.txt and read it line by line. For each line, split the line into a list of words using the split() method. +#The program should build a list of words. +#For each word on each line check to see if the word is already in the list and if not append it to the list. +#When the program completes, sort and print the resulting words in alphabetical order. + +#You can download the sample data at http://www.pythonlearn.com/code/romeo.txt + + +#Begin to write the program with the following code below: +fname = raw_input("Enter file name: ") +fh = open(fname) +fh = fh.split() +lst = list() +fh.append(lst) +for wrd in lst : + print wrd.rstrip() diff --git a/Assignments/Answer_8.5.py b/Assignments/Answer_8.5.py new file mode 100644 index 0000000..bea755c --- /dev/null +++ b/Assignments/Answer_8.5.py @@ -0,0 +1,18 @@ +#8.5 +#Open the file mbox-short.txt and read it line by line. When you find a line that starts with 'From ' like the following line: +#From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008 + +#You will parse the From line using split() and print out the second word in the line (i.e. the entire address of the person +#who sent the message). Then print out a count at the end. +#Hint: make sure not to include the lines that start with 'From:'. + +#You can download the sample data at http://www.pythonlearn.com/code/mbox-short.txt + + +#Begin to write the program with the following code below: +#fname = raw_input("Enter file name: ") +#if len(fname) < 1 : fname = "mbox-short.txt" + +#fh = open(fname) +#count = 0 + diff --git a/Assignments/Class_Notes_21.py b/Assignments/Class_Notes_21.py new file mode 100644 index 0000000..d189473 --- /dev/null +++ b/Assignments/Class_Notes_21.py @@ -0,0 +1,31 @@ +#Class Notes 21 +#for carryon in ['My, Wayward, Son, Therell, Be, Peace, When, You, Are, Done'] +# print carryon +#for SergioIsA in ['potato, head']: +# print "Sergio is a ", SergioIsA + +#friends = ['Joseph', 'Glenn', 'Sally'] +#for friend in friends : +# print 'Happy New Year!', friend +#for i in range(len(friends)) : +# friend = friend[i] +# print friend + +#a = range(10) +#b = range(10) +#d = [] #same as d = list() + +for i in a: + c = a[i] + b[i] + d.append(c) +print d + +#slicing and indexes are the same in lists as they are in strings +a = [1, 2, 3] + +if 2 in a: + b = a.index[2] + a[b] = 'hello' + print a +else : + print 'Not in the list' \ No newline at end of file diff --git a/Assignments/Class_notes14.py b/Assignments/Class_notes14.py new file mode 100644 index 0000000..fbf47ac --- /dev/null +++ b/Assignments/Class_notes14.py @@ -0,0 +1,43 @@ +a = 'hello' +b = 'there' +print a +' '+ b + +num = int(float(1.348572)) +print num + +fruit = "banana" +for letter in fruit: + print letter + +fruit = "banana" +count = 0 +for letter in fruit: + print count, letter + count = count + 1 + +for letter in fruit: + print letter + +s = 'Monty Python' +print s[0:4] +#This prints from the first position called to + #whatever is right before the last position called +print s[6:7] +print s[0:6] +print s[4:10] + +fruit = 'banana' +word = raw_input('Write a word: ') +if word < fruit: + #the signs sort the words alphabetically + #but with the < meaning "comes before" + print 'Word comes after fruit' +elif word > fruit: + print 'Word comes before fruit' +else: + print word + +type(a) +dir(a) +#Allows you to see the string directory that can be applied + # to this string diff --git a/Assignments/Class_notes_!2.py b/Assignments/Class_notes_!2.py new file mode 100644 index 0000000..e69de29 From 8f11d6d14dcc2ca4d75a5032953196b69ab61fb5 Mon Sep 17 00:00:00 2001 From: Guessan Date: Mon, 20 Mar 2017 23:16:42 -0400 Subject: [PATCH 6/6] inserting class notes --- Assignments/Class_notes_17.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Assignments/Class_notes_17.py diff --git a/Assignments/Class_notes_17.py b/Assignments/Class_notes_17.py new file mode 100644 index 0000000..05950fb --- /dev/null +++ b/Assignments/Class_notes_17.py @@ -0,0 +1,13 @@ +# Class Notes for May 7th, 2016 +import urllib +from BeautifulSoup import * + +url = raw_input ('Enter - ') + +openurl = urllib.urlopen(url).read() + +soup = BeautifulSoup(openurl) + +tags = soup('a') + +print tags