When you first learn Python syntax, it is easy to memorize functions, loops, conditionals, and dictionaries separately. In real programs, however, you combine several syntax features to read the current state and decide what to do next.

Farming follows the same structure. You till the field, plant seeds, water them, wait until the crops are fully grown, and then harvest them. If water is limited or the field is dark, you need to check the soil and crop conditions and select only the actions that are needed.

Codedash's Python Farm is a game-based learning environment where you automate this process with block coding and Python code. This guide follows six levels, from basic function calls through dictionaries, nested loops, and state-based problem solving.

Python Farm game screen showing a farmer and five wheat field tiles
Python FarmRun code to move the farmer and automate tilling, planting, watering, and harvesting.
LevelGame MissionCore Syntax
Chapter 1-1 First HarvestHarvest 5 wheat cropsFunction calls and execution order
Chapter 2-5 Farmer BasicsAutomate the process from tilling to harvestingfor, while, and combining functions
Chapter 3-5 Basics - Onion FarmingGrow 25 onions with limited waterGround state and if/else
Chapter 4-1 Check Growth StatusHarvest only 2 ripe tomatoesReading dictionary values
Chapter 6-5 Night Work: Weed Out Wrong CropsRemove crops that do not match the signsDictionaries, conditionals, and nested loops
Chapter 8-3 Legendary 64-Tile PumpkinComplete an 8×8 merged pumpkinTwo-dimensional traversal and state control
EXAMPLE SOLUTIONS

The code in this guide provides example solutions for understanding each level. You can write other code that achieves the same goals.

BLOCK CONVERSION

Some of the block screens below show the results of automatically converting the example Python code in the Block Coding tab for comparison. The blocks available directly from the standard block list may vary depending on your progress through the levels.

FINAL CHALLENGE

The solution code for Chapter 8-3 is withheld to preserve the challenge of the final mission. This guide shows only the completed Legendary 64-Tile Pumpkin just before harvest and the conditions you need to solve.

Core Python Syntax to Know First

01 / GAME API

Game Functions and Enums

Pass directions and crop types to functions to execute the farmer's actions.

move(Dir.Down)
plant(Res.Tomato)
02 / FOR

Fixed-Count Loops

Run the same action a specified number of times.

for i in range(5):
    harvest()
03 / WHILE

Conditional Loops

Wait until a crop is ready, checking its state again each time.

while not can_harvest():
    wait(1)
04 / BRANCH

if/else

Choose a different action based on the current soil or crop state.

if ground == Ground.Tilled:
    water()
else:
    wait(1)
05 / DICTIONARY

Dictionaries

Use keys to read ripeness values or messages on signs.

status = get_res_status()
status['ripeness']
06 / NESTED LOOP

Nested Loops

Combine row and column loops to traverse a large field.

for row in range(4):
    for column in range(5):
        harvest()

Functions such as move(), plant(), and harvest() are not Python built-in functions; they are game-specific functions provided by Python Farm. for, while, if/else, dictionaries, and indentation are actual Python syntax.

Chapter 1-1 First Harvest: Move and Harvest

CHAPTER 1 · LEVEL 1

The goal of the first level is to move down to the field and harvest five ripe wheat crops. Repeat the sequence of calling harvest() on the current tile and then moving to the next tile.

Chapter 1-1 First Harvest wheat field and block coding solution
Chapter 1-1 Level ScreenSee the execution order of movement, harvesting, and fixed-count loop blocks.
Start Python Farm Chapter 1
BLOCK

Solution in Blocks

[Run Code]
  ├─ [Move Down]
  └─ [Repeat 5 Times]
      ├─ [Harvest]
      └─ [If i < 4, Move Right]
PYTHON

Python Code Solution

move(Dir.Down)

for i in range(5):
    harvest()
    if i < 4:
        move(Dir.Right)

There is no need to move again after harvesting the final wheat crop, so the farmer moves right only when i < 4. This level demonstrates function calls, loop counts, and execution order together.

Chapter 2-5 Farmer Basics: From Tilling to Harvesting

CHAPTER 2 · LEVEL 5

In Chapter 2-5, you must till five empty ground tiles, plant tomato seeds, and water them. The crops do not become harvestable immediately, so wait until can_harvest() is true before harvesting.

Chapter 2-5 Farmer Basics field and full farming process block solution
Chapter 2-5 Level ScreenSee the complete farming workflow: tilling → planting → watering → waiting for growth → harvesting.
Start Python Farm Chapter 2
BLOCK

Solution in Blocks

[Repeat While Moving Across 5 Tiles]
  ├─ [Till]
  ├─ [Plant Tomato]
  └─ [Water]

[Repeat While Returning Across 5 Tiles]
  ├─ [Wait Until Harvestable]
  └─ [Harvest]
PYTHON

Python Code Solution

move(Dir.Down)
for i in range(5):
    till()
    plant(Res.Tomato)
    water()
    if i < 4:
        move(Dir.Right)

for i in range(5):
    while not can_harvest():
        wait(1)
    harvest()
    if i < 4:
        move(Dir.Left)

The first for loop repeats the work sequence on each tile, and the second for loop harvests while moving in the opposite direction. The inner while loop checks when each crop has finished growing.

Chapter 3-5 Basics - Onion Farming: Limited Water and if/else

CHAPTER 3 · LEVEL 5

This level asks you to plant and harvest 25 onions in a 5×5 field. You receive exactly 20 units of water, but the five diagonal tiles have already been watered at the start.

Calling water() again on wet soil still consumes water. You must therefore check whether the current ground is Ground.Tilled and water only the dry tiles to complete all 25 tiles. You also need to remove weeds from the field before planting.

Chapter 3-5 onion field with weeds and a block solution using ground-state conditions
Chapter 3-5 Level ScreenCompare a structure that checks for weeds and soil conditions, then uses limited water only on the tiles that need it.
Start Python Farm Chapter 3
BLOCK

Solution in Blocks

[Traverse 5 Rows in a Zigzag]
  ├─ [Clear if Weed]
  ├─ [ground = Ground State]
  ├─ [If Dry Tilled Soil]
  │    ├─ [Plant Onion]
  │    └─ [Water]
  └─ [Otherwise, Plant Onion Only]

[Return Across the Same Field and Harvest]
PYTHON

Python Code Solution

move(Dir.Down)
for row in range(5):
    step = Dir.Right if row % 2 == 0 else Dir.Left
    for i in range(5):
        if get_res_type() == Res.Weed:
            clear()
        ground = get_ground_type()
        if ground == Ground.Tilled:
            plant(Res.Onion)
            water()
        else:
            plant(Res.Onion)
        if i < 4:
            move(step)
    if row < 4:
        move(Dir.Down)

for row in range(5):
    step = Dir.Left if row % 2 == 0 else Dir.Right
    for i in range(5):
        while not can_harvest():
            wait(1)
        harvest()
        if i < 4:
            move(step)
    if row < 4:
        move(Dir.Up)

Use row % 2 to distinguish even and odd rows and reverse the movement direction, allowing you to traverse a large field in a zigzag pattern. The conditional connects the amount of water available with the soil state to prevent unnecessary resource use.

Chapter 4-1 Check Growth Status: Reading Dictionary Values

CHAPTER 4 · LEVEL 1

There are ten tomatoes in the field, but the locations of the ripe tomatoes change each time you run the level. You must harvest only the two tomatoes whose ripeness is 7 or higher; harvesting an unripe tomato causes the mission to fail.

get_res_status() returns the crop state as a dictionary. Reading the value of the ripeness key lets your code decide which crops to harvest instead of relying on color or memorizing their locations.

Chapter 4-1 tomato field and block solution using a ripeness dictionary condition
Chapter 4-1 Level ScreenRead the ripeness value from the state dictionary and select only tomatoes with a value of 7 or higher.
Start Python Farm Chapter 4
BLOCK

Solution in Blocks

[Traverse 2 Rows in a Zigzag]
  ├─ [status = Resource State]
  ├─ [If status exists and ripeness > 6, Harvest]
  └─ [Move to the Next Tile]
PYTHON

Python Code Solution

move(Dir.Down)
for row in range(2):
    step = Dir.Right if row == 0 else Dir.Left
    for i in range(5):
        status = get_res_status()
        if status and status['ripeness'] > 6:
            harvest()
        if i < 4:
            move(step)
    if row < 1:
        move(Dir.Down)

Dictionaries are useful for passing several related states as a single value. In this level, you select and use only the needed ripeness value from resource_type, growthstatus, ripeness, and resource_state.

Chapter 6-5 Night Work: Weed Out Wrong Crops

CHAPTER 6 · LEVEL 5

The nighttime field is dark except around the farmer, so you cannot memorize the locations and types of all crops from the screen in advance. The crop type and quantity to keep in each row are set on that row's sign every time the level runs.

Read the sign's message to find the target crop, and call clear() only when the result of get_res_type() on the current tile differs from the target. Nested loops process the four rows and the four crops in each row.

Chapter 6-5 dark field and block solution for thinning crops based on sign states
Chapter 6-5 Level ScreenRead the sign and current crop states in a dark field, then use conditionals and nested loops to leave only the required crops.
Start Python Farm Chapter 6
BLOCK

Solution in Blocks

[Map Crop Names to Res Values with a Dictionary]
[Repeat for 4 Rows]
  ├─ [target = Crop on Sign]
  ├─ [Move to Crop Tiles]
  ├─ [Repeat for 4 Crops]
  │    └─ [Clear if Different from target]
  └─ [Move to the Next Row's Sign]
PYTHON

Python Code Solution

crops = {
    'tomato': Res.Tomato,
    'onion': Res.Onion,
    'bellpepper': Res.Bellpepper,
    'wheat': Res.Wheat,
}

move(Dir.Down)
for row in range(4):
    target = crops[get_res_status()['message']]
    move(Dir.Right)
    for i in range(4):
        crop = get_res_type()
        if crop is not None and crop != target:
            clear()
        if i < 3:
            move(Dir.Right)
    if row < 3:
        for i in range(4):
            move(Dir.Left)
        move(Dir.Down)

The crops dictionary acts as a lookup table connecting the strings on the signs to actual game resources. The key idea is to base actions on states read at runtime rather than on hard-coded locations or crop types.

Chapter 8-3 Legendary 64-Tile Pumpkin: Final Automation Mission

CHAPTER 8 · LEVEL 3

The final level asks you to grow pumpkins on all 64 tiles of an 8×8 field and merge them into one legendary pumpkin. Ready pumpkins merge when they form a complete square, and the entire 8×8 field must grow correctly to produce a size 64 pumpkin.

Individual pumpkins can rot while growing. Rotten pumpkins are excluded from the merge, so you need to check resource states and selectively repair any problem tiles. This final comprehensive challenge combines nested loops over rows and columns, growth waiting, state checks, and exception handling.

Completed Legendary 64-Tile Pumpkin in the 8×8 field of Chapter 8-3
Chapter 8-3 Just Before HarvestSee the completed size 64 legendary pumpkin covering the entire field.
Take On Python Farm Chapter 8
NO SOLUTION SPOILER

This screen was captured just before harvesting to show the completed pumpkin. The block structure and Python solution code are not provided, preserving the exploration and trial-and-error of the final mission.

Challenge Requirements

  1. You must traverse all 64 tiles of the 8×8 field without missing any.
  2. You must plant a pumpkin on each tile and check its growth state.
  3. Rotten pumpkins cannot merge, so you must find and repair problem tiles.
  4. You must confirm that the merged pumpkin's size is 64.
  5. To clear the actual level, you must harvest the completed legendary pumpkin.

Why It Helps to View Block Coding and Python Code Together

01 / STRUCTURE

The Execution Structure Becomes Visible

The block layout clearly shows the order of tilling, planting, and watering, the two execution branches of if/else, and the nested row and column loops.

02 / TRANSLATE

Express the Same Farming Process with Real Syntax

Compare how loop structures in blocks become for, while, range(), and indentation.

03 / PURPOSE

Syntax Gains a Practical Purpose

Loops process a large field, conditionals conserve water, and dictionaries connect signs with crop states.

04 / FEEDBACK

See the Results Immediately

Run the code to see the farmer move and crop states change on screen; if the result differs from your expectation, revise the code and run it again.

Codedash runs in the browser without requiring a separate Python environment. After examining the structure with blocks, you can express the same problem again in Python code and gradually expand the scope of your automation.

Use Classroom Features in Lessons

CLASSROOM WORKFLOW

In a Codedash classroom, instructors can check each student's current level and completion progress. Before clearing a level, a student can use Request Help to submit their current code. Once they clear the level, the completed code is recorded separately as the final submission. Instructors can open and run either submission to identify whether the student is stuck on a loop's movement route or a conditional's state comparison and provide guidance.

You can teach the five-tile harvest pattern first and then extend the same pattern to a 5×5 field, or compare code that students wrote to solve different sign results.

Explore Core Python Syntax on the Farm Now

All ten levels in Chapter 1 and Chapter 2 are available without signing in or paying. Starting with movement and harvesting, the automation gradually expands to tilling, planting, watering, and waiting for growth.

Start Python Farm Chapter 1

Chapter 2 unlocks after you complete the five levels in Chapter 1.

Later chapters also cannot be skipped; each one unlocks only after you complete the preceding chapter. To access Chapter 3 and later as an individual user, sign in and purchase access or obtain access with a redemption code. Purchased access remains available for 365 days from the payment date.

Frequently Asked Questions

Are all Python Farm functions built-in Python functions?

No. move(), harvest(), plant(), and get_res_status() are game-specific functions provided by Python Farm. Features such as for, while, if/else, and dictionaries are actual Python syntax.

Do I have to solve every level using only block coding?

No. In Python Farm, you can switch between the Block Coding and Python tabs. You can inspect the structure with blocks first or write Python code directly.

Can I water every tile in Chapter 3-5?

No. You have only 20 units of water, and five tiles have already been watered. Calling water() on an already wet tile still consumes water, so check the soil state and water only the 20 dry tiles.

Why is there no solution code for Chapter 8-3?

The Legendary 64-Tile Pumpkin is a final mission that combines movement, nested loops, state checks, and exception handling learned earlier. The completed goal is shown, but the solution code is withheld so you can retain the challenge of designing the algorithm yourself.

Are Chapter 3 and later levels also free?

No. Chapter 1 and Chapter 2 are currently free without signing in. To access paid chapters from Chapter 3 onward as an individual user, you need to sign in and purchase access or receive access through redemption, and you must complete the preceding chapters first. Purchased access remains available for 365 days from the payment date.