def display_lines(file_path, num_lines): with open(file_path, 'r') as file: lines = file.readlines() for i in range(min(num_lines, len(lines))): print(lines[i], end='') def calculate_word_frequency(file_path, word): with open(file_path, 'r') as file: text = file.read() word_count = text.lower().split().count(word.lower()) return word_count def main(): file_path = input("Enter the name of the text file: ") try: with open(file_path, 'r') as file: pass except FileNotFoundError: print(f"The file {file_path} does not exist.") return num_lines = int(input("Enter the number of lines to display: ")) display_lines(file_path, num_lines) word = input("\nEnter the word to calculate its frequency: ") frequency = calculate_word_frequency(file_path, word) print(f"The word '{word}' appears {frequency} times in the file.") if __name__ == "__main__": main()