Upload files to "TaskA01"
This commit is contained in:
parent
ff32669e96
commit
b8cbfda8b5
24
TaskA01/run.py
Normal file
24
TaskA01/run.py
Normal file
@ -0,0 +1,24 @@
|
||||
import os
|
||||
|
||||
def TaskA01(file_path):
|
||||
with open(file_path, 'r',encoding='utf-8') as file:
|
||||
line_number = 0
|
||||
for line in file:
|
||||
line_number += 1
|
||||
words = []
|
||||
current_word = ''
|
||||
for char in line:
|
||||
if char.isalnum():
|
||||
current_word += char
|
||||
elif current_word:
|
||||
words.append(current_word)
|
||||
current_word = ''
|
||||
if current_word:
|
||||
words.append(current_word)
|
||||
|
||||
if "Hamlet" in words:
|
||||
print(f"Line {line_number}: {line}")
|
||||
|
||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
file_path = os.path.join(script_dir, 'shakespeare.exp')
|
||||
TaskA01(file_path)
|
Loading…
Reference in New Issue
Block a user