Assignment on Python

Added on - 13 Sep 2019

  • 1

    pages

  • 557

    words

  • 126

    views

  • 0

    downloads

Showing pages 1 to 1 of 1 pages
Assignment #1Write a program to open the file romeo.txt and read it line by line. For each line, split the line into a listof words using the split function.For each word, check to see if the word is already in a list. If the word is not in the list, add it to the list.When the program completes, sort and print the resulting words in alphabetical order.HINT:1.Download the text file: romeo.txt fromhttp://www.pythonlearn.com/code3/romeo.txtto yourlocal machine. For ease, place this file in the same folder as the .py file for this assignment.2.Create and initialize a list to collect unique words.3.Prompt the user for the file name. Use a try-except block to exit with a user-friendly errormessage if there is an error opening the file name specified.4.Once the file is open, use an iterative loop (e.g. “for” or “while”) to traverse each line of the file.5.Use the “split” function to split the line into individual words and collect these in a list. Note –remember to check for the condition that the line may be empty, i.e. not contain any words!6.Check each word against our collection of unique words. If it does not exist, add it in.7.When the program has finished traversing each line in the specified file, sort the completecollection of unique words in alphabetical order by apply the “sort” function.8.Remember your Python code will be graded according to our class Rubric.9.Submit your Python code file. Name it “XXXX-Romeo.py” where XXXX is your name.10.Submit also a Word document showing screen shots of the various testing conditions. Goodprogrammers test all cases, so you should make sure you show tests for erroneous inputs.Be sure to comment your program adequately!Assignment #2Write a program that categorizes each mail message by which day of the week the commit was done. Todo this look for lines that start with “From”, then look for the third word and keep a running count ofeach of the days of the week. At the end of the program print out the contents of your dictionary (orderdoes not matter).The input file you will use for this is the ‘mbox.txt’ file, first introduced in Severance Section 7.3. It canbe found athttp://www.pythonlearn.com/code3/mbox.txt. A shorter file for debugging can be found athttp://www.pythonlearn.com/code3/mbox-short.txt.1.Remember your Python code will be graded according to our class Rubric.2.Submit your Python code file. Name it “XXXX-day.py” where XXXX is your name.3.Submit also a Word document showing screen shots of the various testing conditions. Goodprogrammers test all cases, so you should make sure you show tests for erroneous inputs. Makesure you submit test results from the full mbox.txt file (and not from the mbox-short.txt file.)Be sure to comment your program adequately!