Created
October 25, 2025 04:56
-
-
Save vtu27619/6f7f27c00b497820d0a8b6ce0e1ef6af to your computer and use it in GitHub Desktop.
Likitha
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Task6a | |
| def copy_files(file_paths): | |
| for file_path in file_paths: | |
| if os.path.exists(file_path): | |
| with open(file_path, 'r') as original_file: | |
| original_content = original_file.read() | |
| copy_file_path = file_path.split('.')[0] + '_copy.' + file_path.split('.')[1] | |
| with open(copy_file_path, 'w') as copy_file: | |
| copy_file.write(original_content) | |
| print(f"Contents copied from {file_path} to {copy_file_path} successfully.") | |
| else: | |
| print(f"Error: File '{file_path}' not found.") | |
| # Example usage: | |
| import os | |
| file_list = ['file1.txt', 'file2.txt', 'file3.txt'] # List of file paths | |
| copy_files(file_list) | |
| Task6b | |
| def write_employee_report(filename): | |
| employees = [ | |
| {"name": "Alice", "department": "HR"}, | |
| {"name": "Bob", "department": "Engineering"}, | |
| {"name": "Charlie", "department": "Finance"} | |
| ] | |
| with open(filename, "w") as file: | |
| for employee in employees: | |
| line = f"Name: {employee['name']}, Department: {employee['department']}\n" | |
| file.write(line) | |
| # Example usage: | |
| write_employee_report("employee_report.txt") | |
| Task6c | |
| def teacher_notes_word_count(): | |
| # Step 1: Create a file and write student notes | |
| file_name = input("Enter the file name: ") | |
| with open(file_name, 'w') as file: | |
| print("Enter student notes (press Enter on an empty line to stop):") | |
| while True: | |
| line = input() | |
| if not line: | |
| break | |
| file.write(line + '\n') | |
| # Step 2: Display the content of the file | |
| print("\nFile Content:") | |
| with open(file_name, 'r') as file: | |
| content = file.read() | |
| print(content) | |
| # Step 3: Count occurrences of a chosen word | |
| word = input("Enter the word to count: ") | |
| count = content.split().count(word) | |
| print(f"\nThe word '{word}' occurs {count} times.") | |
| # Run the program | |
| teacher_notes_word_count() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment