Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Weather Log Update | Advanced File Handling & Context Managers
Python Structural Programming
Seksjon 2. Kapittel 2
single

single

Challenge: Weather Log Update

Sveip for å vise menyen

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.

Oppgave

Sveip for å begynne å kode

Complete the following steps to implement the Weather Log Update Challenge:

  • Open a file named weather_log.txt in 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.

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 2
single

single

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

some-alt