Ask a question from expert

Ask now

Assignment on Python

1 Pages557 Words562 Views
   

Added on  2019-09-13

Assignment on Python

   Added on 2019-09-13

BookmarkShareRelated Documents
Assignment #1Write a program to 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 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 from http://www.pythonlearn.com/code3/romeo.txtto your local 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 error message 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 complete collection 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. Good programmers 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 of each of the days of the week. At the end of the program print out the contents of your dictionary (order does not matter).The input file you will use for this is the ‘mbox.txt’ file, first introduced in Severance Section 7.3. It can be found at http://www.pythonlearn.com/code3/mbox.txt. A shorter file for debugging can be found at http://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. Good programmers 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!
Assignment on Python_1

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Program to Promote Files
|1
|438
|428

UMUC Data 620 Assignment 8.3.
|2
|386
|387

The Programming Paradigms : Assignment
|3
|1194
|607

ITECH1400 – Foundations of Programming
|7
|1303
|94

Python Programming: Research Report
|7
|2904
|737

TCSS142 Computer Science and Systems
|8
|2141
|359