Question

Hello, I need your help with my PYTHON 3 ASSIGNMENT: SO HERE IS THE ASSIGNMENT ITSELF:...

Hello,

I need your help with my PYTHON 3 ASSIGNMENT:

SO HERE IS THE ASSIGNMENT ITSELF:

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.py4e.com/code3/romeo.txt

HERE IS THE DESIRED OUTPUT:

['Arise', 'But', 'It', 'Juliet', 'Who', 'already', 'and', 'breaks', 'east', 'envious', 'fair', 'grief', 'is', 'kill', 'light', 'moon', 'pale', 'sick', 'soft', 'sun', 'the', 'through', 'what', 'window', 'with', 'yonder']

HERE IS MY CODE WHICH I WILL NEED YOU TO USE AND MODIFY AS NEEDED:

fname=input("Enter the file name")
frapucchino = open(fname)
# Opening romeo.txt
capucchino = []
# Declaring Empty List
for line in frapucchino:
words = line.split()
for word in words:
print(word)
capucchino.sort(word)
if word not in capucchino:
capucchino.append(word.rstrip())
print (capucchino.sort())

I AM HAVING A PROBLEM WITH SORTING THE OUTPUT IN THE ALPHABETIC ORDER (FIRST GOES THE CAPITAL LETTERS AND THEN LOWER CASE LETTERS AND ALL IN THE ALPHABETIC ORDER. I AM NOT SURE HOW TO CORRECTLY USE SORT() METHOD. SO PLEASE HELP ME WITH THAT AND MATCH THE DESIRED OUTPUT.

ALSO PLEASE TAKE A PICTURE(SNAPCHAT) OF YOUR CODE IN YOUR COMPUTER OR COME UP WITH SOMETHING ELSE, BUT JUST MAKE SURE THAT I CAN SEE YOUR INDENT. PLEASE FOLLOW THE RULES OF INDENT AND SHOW ME YOUR INDENT, BECAUSE I WILL NEED INDENT(THE SPACE NEEDED PRIOR EACH LINE OF CODE) FOR BEING ABLE TO RUN THE CODE IN THE PROGRAM.

Please consider helping me. I am looking forward to hearing back from you!

Thank you a lot!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

romeo.txt (Text File)

Output

Add a comment
Know the answer?
Add Answer to:
Hello, I need your help with my PYTHON 3 ASSIGNMENT: SO HERE IS THE ASSIGNMENT ITSELF:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT