Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Indentation Rescue | Syntax and Indentation Pitfalls
Common Python Mistakes and How to Fix Them

bookChallenge: Indentation Rescue

In Python, indentation is not just a matter of style—it defines the structure of your code and determines how statements are grouped together. Misplaced or inconsistent indentation, especially in code with multiple nested if-else statements and loops, can lead to unexpected behavior or errors that are sometimes hard to spot. To build your confidence in handling real-world code, you will now tackle a hands-on challenge where you must rescue a function suffering from mixed-up indentation.

Oppgave

Swipe to start coding

Your goal is to correct the indentation in the process_numbers function so that it executes as intended.

  • Ensure that all nested blocks for if, elif, else, and for statements are properly indented.
  • Make sure that print statements are executed in the correct logical branches.
  • Do not change the logic or add/remove any statements—only fix the indentation.

Løsning

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. 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

Suggested prompts:

Can you show me the function with the mixed-up indentation?

What are some common indentation errors to look out for in Python?

Can you give me tips for fixing indentation issues in complex code?

close

Awesome!

Completion rate improved to 5.26

bookChallenge: Indentation Rescue

Sveip for å vise menyen

In Python, indentation is not just a matter of style—it defines the structure of your code and determines how statements are grouped together. Misplaced or inconsistent indentation, especially in code with multiple nested if-else statements and loops, can lead to unexpected behavior or errors that are sometimes hard to spot. To build your confidence in handling real-world code, you will now tackle a hands-on challenge where you must rescue a function suffering from mixed-up indentation.

Oppgave

Swipe to start coding

Your goal is to correct the indentation in the process_numbers function so that it executes as intended.

  • Ensure that all nested blocks for if, elif, else, and for statements are properly indented.
  • Make sure that print statements are executed in the correct logical branches.
  • Do not change the logic or add/remove any statements—only fix the indentation.

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 1. Kapittel 4
single

single

some-alt