Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära 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.

Uppgift

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

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 2. Kapitel 4
single

single

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

Suggested prompts:

Can you show me the original Python function that needs to be refactored?

What are the main tasks that the current function performs?

Do you have any specific requirements for naming the helper functions?

close

Awesome!

Completion rate improved to 5.26

bookChallenge: Extract Functions

Svep för att visa menyn

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.

Uppgift

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 desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 2. Kapitel 4
single

single

some-alt