diff --git a/Assignments/Assignment_5.2 b/Assignments/Assignment_5.2 new file mode 100644 index 0000000..9c3adef --- /dev/null +++ b/Assignments/Assignment_5.2 @@ -0,0 +1,21 @@ +Hello Fellows! + +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 + + + +Happy Coding, +Tunisia diff --git a/Assignments/Assignment_6.5 b/Assignments/Assignment_6.5 new file mode 100644 index 0000000..c2f5082 --- /dev/null +++ b/Assignments/Assignment_6.5 @@ -0,0 +1,12 @@ +Hello Fellows! + +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"; + + + +Happy Coding, +Tunisia diff --git a/Assignments/Assignment_7.1 b/Assignments/Assignment_7.1 new file mode 100644 index 0000000..eab2a65 --- /dev/null +++ b/Assignments/Assignment_7.1 @@ -0,0 +1,46 @@ +Hello Fellows! + +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) + + + +Happy Coding, +Tunisia + +P.S. The link: http://www.pythonlearn.com/code/words.txt, contains the following words: +WRITING PROGRAMS OR PROGRAMMING IS A VERY CREATIVE +AND REWARDING ACTIVITY YOU CAN WRITE PROGRAMS FOR +MANY REASONS RANGING FROM MAKING YOUR LIVING TO SOLVING +A DIFFICULT DATA ANALYSIS PROBLEM TO HAVING FUN TO HELPING +SOMEONE ELSE SOLVE A PROBLEM THIS BOOK ASSUMES THAT +{\EM EVERYONE} NEEDS TO KNOW HOW TO PROGRAM AND THAT ONCE +YOU KNOW HOW TO PROGRAM, YOU WILL FIGURE OUT WHAT YOU WANT +TO DO WITH YOUR NEWFOUND SKILLS + +WE ARE SURROUNDED IN OUR DAILY LIVES WITH COMPUTERS RANGING +FROM LAPTOPS TO CELL PHONES WE CAN THINK OF THESE COMPUTERS +AS OUR PERSONAL ASSISTANTS WHO CAN TAKE CARE OF MANY THINGS +ON OUR BEHALF THE HARDWARE IN OUR CURRENT-DAY COMPUTERS +IS ESSENTIALLY BUILT TO CONTINUOUSLY AS US THE QUESTION +WHAT WOULD YOU LIKE ME TO DO NEXT + +OUR COMPUTERS ARE FAST AND HAVE VASTS AMOUNTS OF MEMORY AND +COULD BE VERY HELPFUL TO US IF WE ONLY KNEW THE LANGUAGE TO +SPEAK TO EXPLAIN TO THE COMPUTER WHAT WE WOULD LIKE IT TO +DO NEXT IF WE KNEW THIS LANGUAGE WE COULD TELL THE +COMPUTER TO DO TASKS ON OUR BEHALF THAT WERE REPTITIVE +INTERESTINGLY, THE KINDS OF THINGS COMPUTERS CAN DO BEST +ARE OFTEN THE KINDS OF THINGS THAT WE HUMANS FIND BORING +AND MIND-NUMBING + + + diff --git a/Assignments/Assignment_7.3 b/Assignments/Assignment_7.3 new file mode 100644 index 0000000..eb69709 --- /dev/null +++ b/Assignments/Assignment_7.3 @@ -0,0 +1,16 @@ +Hello Fellows! + +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. + + + +Happy Coding, +Tunisia diff --git a/Assignments/Assignment_8.4 b/Assignments/Assignment_8.4 new file mode 100644 index 0000000..7f33a3c --- /dev/null +++ b/Assignments/Assignment_8.4 @@ -0,0 +1,20 @@ +Hello Fellows! + +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() + + +Happy Coding! +Tunisia diff --git a/Assignments/Assignment_8.5 b/Assignments/Assignment_8.5 new file mode 100644 index 0000000..053f1a1 --- /dev/null +++ b/Assignments/Assignment_8.5 @@ -0,0 +1,24 @@ +Hello Fellows! + +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 + +print "There were", count, "lines in the file with From as the first word" + + +Happy Coding! +Tunisia diff --git a/Slides/04-19-16-Files.pdf b/Slides/04-19-16-Files.pdf new file mode 100644 index 0000000..2cd2807 Binary files /dev/null and b/Slides/04-19-16-Files.pdf differ diff --git a/Slides/04-21-16-Lists.pdf b/Slides/04-21-16-Lists.pdf new file mode 100644 index 0000000..9c05259 Binary files /dev/null and b/Slides/04-21-16-Lists.pdf differ diff --git a/Slides/04-26-16-Dictionaries.pdf b/Slides/04-26-16-Dictionaries.pdf new file mode 100644 index 0000000..acade65 Binary files /dev/null and b/Slides/04-26-16-Dictionaries.pdf differ diff --git a/Slides/04-28-16-Tuples.pdf b/Slides/04-28-16-Tuples.pdf new file mode 100644 index 0000000..d6598e6 Binary files /dev/null and b/Slides/04-28-16-Tuples.pdf differ