Practice Summary (28.2.8) - Handling files - Part B - Data Structures and Algorithms in Python
Students

Academic Programs

AI-powered learning for grades 8-12, aligned with major curricula

Professional

Professional Courses

Industry-relevant training in Business, Technology, and Design

Games

Interactive Games

Fun games to boost memory, math, typing, and English skills

Summary

Practice - Summary

Learning

Practice Questions

Test your understanding with targeted questions

Question 1 Easy

What method is used to write a single string to a file?

💡 Hint: It's the simplest way to write text.

Question 2 Easy

How do you read all lines from a file?

💡 Hint: Think of collecting all lines into a list.

4 more questions available

Interactive Quizzes

Quick quizzes to reinforce your learning

Question 1

What method is used to write a single string to a file?

write()
writelines()
print()

💡 Hint: It's a fundamental method for file operations.

Question 2

True or False: writelines() adds newline characters automatically.

True
False

💡 Hint: Think about how this method works with lists.

2 more questions available

Challenge Problems

Push your limits with advanced challenges

Challenge 1 Hard

Write a function that reads a file and counts the number of lines that include a specific word, then writes those lines to a new file.

💡 Hint: Think about how to efficiently read and filter data.

Challenge 2 Hard

You are given a list of strings that contain user messages. Write a function that writes only the non-empty messages to a file but excludes any message that ends with a space.

💡 Hint: Consider using list comprehension for a shorter solution.

Get performance evaluation

Reference links

Supplementary resources to enhance your learning experience.