Chỉ em hướng làm bài tập này với ạ

Em đang học python 3 trên trang web www.py4e.com của Dr. Charles Russell Severance
Chỉ em hướng giải quyết bài này.

Exercise 4: Download a copy of the file from www.py4e.com/code3/romeo.txt.

Write 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.

— Làm sao được đáp án như này ạ:
Enter file: romeo.txt
['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']

Bạn hỏi xin code hay nhờ sửa lỗi sai. Đọc kĩ phần hướng dẫn bằng tiếng Anh sẽ có cách giải

1 Like

Trước tiên là bạn phải mở file .text ra
sau đó là đọc file a = file.read()
rồi print ra và sử dụng .split là xong

1 Like
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?