Section 2. Chapitre 2
single
Challenge: Weather Log Update
Glissez pour afficher le menu
In this challenge, you will apply advanced file handling techniques in Python to update and manage a weather log. You will use different file modes - such as write ("w"), append ("a"), read and write ("r+"), and read ("r") - to perform specific operations on the same file.
Tâche
Glissez pour commencer à coder
Complete the following steps to implement the Weather Log Update Challenge:
- Open a file named
weather_log.txtin write mode and write the header line:Status: Pending. - Open the same file in append mode and add two lines: one for Monday (
Monday: 22°C, Sunny) and one for Tuesday (Tuesday: 19°C, Rainy). - Open the file in read and write mode (
r+), move the file pointer to the beginning, and overwrite the word "Pending" with "Updated" in the header line. - Finally, open the file in read mode and print its contents to the console to verify your changes.
Solution
Tout était clair ?
Merci pour vos commentaires !
Section 2. Chapitre 2
single
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion