Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Extract Functions | Refactoring Techniques
Code Quality and Refactoring in Python

bookChallenge: Extract Functions

In this challenge, you will apply the extract function technique to improve a Python script. You are given a long function that performs several tasks in sequence, making it harder to read and maintain. Your goal is to refactor this function by breaking it into at least two smaller, well-named helper functions. This approach will help you organize the logic, make each part easier to understand, and improve the overall code quality.

Oppgave

Swipe to start coding

Refactor the provided process_data function by extracting at least two helper functions. Each helper function should have a clear, descriptive name and handle a distinct part of the logic. Update process_data to use these new helper functions.

Steps:

  • Identify logical sections within the process_data function that can be separated.
  • Move each section into a new function with a meaningful name.
  • Replace the original code in process_data with calls to your helper functions.
  • Do not change the external behavior or output of the function.

Løsning

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 4
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

close

Awesome!

Completion rate improved to 5.26

bookChallenge: Extract Functions

Sveip for å vise menyen

In this challenge, you will apply the extract function technique to improve a Python script. You are given a long function that performs several tasks in sequence, making it harder to read and maintain. Your goal is to refactor this function by breaking it into at least two smaller, well-named helper functions. This approach will help you organize the logic, make each part easier to understand, and improve the overall code quality.

Oppgave

Swipe to start coding

Refactor the provided process_data function by extracting at least two helper functions. Each helper function should have a clear, descriptive name and handle a distinct part of the logic. Update process_data to use these new helper functions.

Steps:

  • Identify logical sections within the process_data function that can be separated.
  • Move each section into a new function with a meaningful name.
  • Replace the original code in process_data with calls to your helper functions.
  • Do not change the external behavior or output of the function.

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 4
single

single

some-alt