Week 4 Unit 4: Exercise

22. October 2024

The file numbers.txt contains numbers. (Actually, the same numbers from the last exercise.) There is exactly one number per line. Read the numbers from the file and write only the even numbers into a new file named even_numbers.txt. Again, there should be one number per line. The order of the numbers shall be unchanged. To indicate that the program is finished, print the following output: List of even numbers created!

Hint

First read all the numbers as explained in the last exercise and put them into a list. Open the new file for writing. Go through the list and check if a number is even. If this is the case, change the integer into a string and do not forget to add a line break. Write this string into the file. Finally implement the print statement.


< Previous unit | Next unit > | Course Overview