Practice Removing Trailing White Space (28.2.7) - Handling files - Part B
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

Removing Trailing White Space

Practice - Removing Trailing White Space

Learning

Practice Questions

Test your understanding with targeted questions

Question 1 Easy

What does the write() method do?

💡 Hint: Think about how you add text to a document.

Question 2 Easy

Define trailing white space.

💡 Hint: Consider what happens when writing text.

4 more questions available

Interactive Quizzes

Quick quizzes to reinforce your learning

Question 1

What method writes a single string to a file?

write()
writelines()
read()

💡 Hint: Which method allows you to add text directly?

Question 2

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

True
False

💡 Hint: Think about how `writelines()` handles multiple strings.

2 more questions available

Challenge Problems

Push your limits with advanced challenges

Challenge 1 Hard

Write a function that reads all lines from 'input.txt', removes trailing whitespace, and writes to 'output.txt'. Explain how you would handle errors if the file cannot be opened.

💡 Hint: What will you need to use for error handling?

Challenge 2 Hard

Create a script that checks if a line ends with a whitespace character and if so, warns the user. How would you implement this check within your existing file processing code?

💡 Hint: Think about how to incorporate this check in the reading or writing loop.

Get performance evaluation

Reference links

Supplementary resources to enhance your learning experience.