The Farmer Was Replaced

The Farmer Was Replaced

Not enough ratings
RoboCulture 101: AgBot Python Programming for Beginners
By chaosbreaker
Goal: To equip beginners with the foundational knowledge to ask informed questions and understand advanced programming tutorials (e.g., on YouTube).

About This Guide: This workbook is for individuals new to coding who may face an experience paradox, where you have to know how to code to paste code on forums to ask for help. However if you cannot code, you cannot ask for coding help. Do the tasks in this workbook to break through the paradox. The workbook contains ten tasks designed to progressively introduce coding concepts based on the The Farmer Was Replaced, tech tree. The learning pace and tech unlocks are intentionally slow to allow for ample practice. Each new tech is referenced from the in-game documentation (I show you where), and variations of the documentation examples are used for practice. The code examples will be deliberately padded, including extra elements to reinforce newly learned concepts. Completing this workbook will cover approximately 50% of the tech tree, providing enough coding knowledge to seek help on online forums.

📗 Using the In-Game Documentation: Throughout the workbook, you will be directed to specific in-game documentation. For example: "Have the Tuples doc handy -- [ i ] ➡️ Programming ➡️ Tuples."

📺 Supplementary Video Resources: Where relevant, links to concise YouTube videos explaining coding concepts will be provided.
   
Award
Favorite
Favorited
Unfavorite
🌾 🌾 🌾 PART I: Introduction 🌾 🌾 🌾 🌾
⚜️ PART I -- intro
We delve into creating tiny programs by following the game documentation.

How to Use This Workbook Effectively:
The tasks are presented first, and the corresponding answer key is located at the end.
Before consulting the answer key, make a genuine attempt to solve each task or at least formulate a guess to engage your mind. For example, when asked to define a tuple named "fibonacci" with five elements, first consult the indicated documentation, then try to solve it before checking the answer key.

Initially, the tasks will provide explicit instructions. From Task 6 onwards, you will receive more hints and broader goals to encourage problem-solving.
Complete Task 5 and then restart the game.
After finishing Task 10, restart the game again.


If you are brand new to coding and find The Farmer Was Replaced too hard I recommend these, in order of difficulty, easy to hard:
  1. Lightbot -- Hour of Code -- online Flash $0
  2. One Dreamer -- Steam -- demo available
  3. Modulo Code -- Microsoft Store $0
  4. May's Journey -- Steam -- $0
  5. Sam & MaRU -- Steam
📝 Task 01 - 🔓 While Loop Tech
Goals -- learn how functions and crop growth cycle works + unlock Loop tech.

Note:
📺 What are Functions? Coding for Kids | Kodable -- https://youtu.be/3JIZ40yuZL0?si=LF4RG9XB4xx-0oLq

* Comments are preceded by # -- read [ i ] ➡️ Programming ➡️ Comments
* Functions are runnable, small sets of code that are identified by appended “()”.
* Verify the unlock costs for Loops on the tech tree -- [ Unlocks ] ➡️ (mouse over) [ Loops ] ➡️ 5 Hay
* Have the First Program window handy -- [ i ] ➡️ General Info ➡️ First Program

1. First Program shows two statements harvest() and do_a_flip()
2. Create Program P01 -- Section 1 -- 5ver
  • i. Define (type out) harvest() five times (refer to aforementioned First Program).
  • ii. Run and observe before proceeding to Section 2.
3. Observe that the Hay Items (inventory) on the upper left of the screen is less than 5 because the drone is harvesting prematurely.
4. Create Program P01 -- Section 2 -- Wait for it
  • i. What can the drone do to give time for 🌾 grass to grow back between harvest?
  • ii. Hint -- Acrobatics
  • iii. Solution -- run harvest() five more times but perform a do_a_flip() between each harvest().
  • iv. Observe that Hay inventory has increased by 5 (refer to First Program)
5. Loop unlock requirements met -- unlock Loops in the tech tree -- [ Unlocks ] ➡️ (click) Loops .
6. Observe that unlocking tech can trigger an info window popup -- While Loop.

📝 Task 02 - 🔓 Speed Tech
Goals -- explore while true and while false loops + unlock Speed tech.

Note:
📺 Coding Basics: While Loops & Do While Loops | Programming for Beginners | Transcode
📰 the game does not offer do-while. https://youtu.be/v-K-4KuA8mQ?si=XBo_7OdGcgmU30gn
* You can now invoke builtin functions.
* Verify the unlock costs for Loops on the tech tree -- [ Unlocks ] ➡️ (mouse over) [ Speed ] ➡️ 20 Hay
* Have the While Loop doc handy -- [ i ] ➡️ Unlocks ➡️ Loops

1. Read the While loop info window.
2. Create Program P02 -- Under These Circumstances
  • i. Define two while loops, one that performs a flip under False conditions and another that harvests under True conditions.
  • ii. Hint -- While Loop, the examples near the end of doc.
  • Iii. Solution -- declare while(False) run code block: do_a_flip() then declare while(True) run code block: harvest()
  • iv. Observe that no flips are performed.
  • v. Observe that an infinite loop occurs and you only escape by terminating the program.
4. Stop program when the reaping goal of 20 Hay is met.
5. Unlock Speed in the tech tree, triggering Speed Upgrade info window popup
📝 Task 03 - 🔓 Expand Tech
Goals -- Explore if statements and can_harvest() function + Unlock Expand tech.

Note:
* Verify Expand tech unlock cost of 30 Hay.
* Have the Speed Upgrade doc handy -- [ i ] ➡️ Unlocks ➡️ Speed
* From this point, read the new tech unlock docs without reminder -- commonly known in the tech field as RTFM (read the fine manual).

1. Create Program P03.
  • i. Define a function that if harvest is possible, harvests.
  • ii. Hint -- Read the fine manual (RTFM) -- [ i ] ➡️ Unlocks ➡️ Speed
  • iii. Solution -- define a while(True) function that runs blockcode: harvest()
  • iv. Observe that harvesting is always successful since no premature harvest is performed.
  • v. Note that infinite loops will keep occurring until we find a fix.
2. Stop when the reaping goal of 30 Hay is met.
3. Unlock Expand tech triggering Expand 1 popup.
📝 Task 04 - 🔓 Plant Tech
Goals -- Explore the movement function + unlock Plant tech

Note:
What is Python? Why Python is So Popular? | Programming with Mosh
https://youtu.be/Y8Tko2YC5hA?si=wI23ZwrjuEbd8g2k
* Verify Plant tech unlock cost of 50 Hay
* Have the Expand 1 doc handy -- [ i ] ➡️ Unlocks ➡️ Expand

1. Create and run Program P04 -- The Haymaker
  • i. Check if harvest is possible, harvest, then move South.
  • ii. Hint -- It’s similar to P03
  • iii. Solution -- define a while(True) function that runs blockcode: harvest(), move(South)
2. Stop program to break the infinite loop when Plant tech unlock requirements of 50 Hay is met.
3. Unlock Plant tech, triggering Plant popup.
📝 Task 05 - 🔓 Debug Tech
Goals -- Explore plant() function by harvesting Wood + unlock Debug tech

* Verify Debug tech unlock cost of 100 Hay and 100 Wood.
* 🌳 Bush does not grow automatically--must be planted.
* Have the Plant doc handy -- [ i ] ➡️ Unlocks ➡️ Plant

1. Run P04 from Task 4 to harvest 100 Hay.
2. Create Program P05
  • i. If can harvest, harvest, plant bush then move North
  • ii. Hint -- It’s similar to the previous program but with Bush planting.
  • iii. Solution -- define a while(True) function that runs blockcode: harvest(), plant(Entities.Bush),
  • move(North)
2. Stop program when Plant tech unlock requirements are met.
3. Unlock Debug tech, triggering Debug popup.
👋⏪ Mid Term Project + Restart
👋 Mid Term project -- Hello World
The Hello World program is often the first program written by students. Watch the video then write the hello world program in a browser based coding environment.

How:
📺 Hello World in Python || Python Tutorial || Python Programming | Socratica
https://youtu.be/KOdfpbnWLVo?si=1-zGlNBruBv7PGGW

Where: Python Online Compiler - Code Editor[www.programiz.com]

⏹️⏪▶️
Restart the game and try to get back here without looking at the Answer Key.
🌲 🌲 🌲 PART II: Alea Iacta Est 🌲 🌲 🌲 🌲
⚜️ PART II -- Alea Iacta Est

Unleash your creativity because the game really begins. You have unlocked enough techs that you can make more complex and clever programs. Until Task 09 we will over harvest and reap what you have in inventory plus the unlock cost to practice printing function and operators.
📝 Task 06 - 🔓 Operators and Senses Tech
Goals -- explore the clear() then the print() function + unlock Operators and Senses tech

Note:
📺 Coding Basics: If Statements, If Else, Else - Coding Tutorial For Java, C, and C++! | Transcode
📰 the concept is same for Pyhton
https://youtu.be/HQ3dCWjfRZ4?si=k7f7vkuCIDcqDIA2
* Verify Operators tech unlock cost of 300 Hay 30 Wood
* Verify Senses tech unlock cost of 200 Hay
* Reaping goal is 500 Hay and 30 Wood
* Have the Plant doc handy -- [ i ] ➡️ Unlocks ➡️ Debug
* Have the If doc handy -- [ i ] ➡️ Programming ➡️ If
* Debug mode -- if you click the left margin in the code window, a red dot will appear that will slow your run to step-by-step confirmation mode.

We need to harvest both Wood and Hay but Wood takes longer to grow. Therefore we will allocate two square plots out of three for 🌳 Bush and one for 🌾 Grass. The field will look like this:
🌾
🌳
🌳

1. Create Program P06 -- Section 1 -- Practice: Burrrrr
  • i. Hint -- Straight out of Debug doc.
  • ii. Sowing -- try the print function by printing the 0 and 7734, then clear the field.
  • iii. Input 0, 7734 into print(), clear().
  • iv. Run and observe before proceeding to the next section.
  • v. Observe that some function can take multiple inputs -- 0 and 7734 -- 07734 is hello in pager-speak (read upside-down)
  • vi. Observe that you can print to the screen, numbers (not words/strings)
  • vii. Observe that clear() restores the field as Grassland.

2. Create Program P06 -- Section 2 -- Hay is for horses 🌾
  • i. We are going to create a function that plants and harvests three times: Hay, Wood, then Wood.
  • ii. Define a function that while True, runs blocks of code. Create an if statement that checks if harvest is possible then harvests. Regardless of harvest possibility, move north.
  • iii. Hint -- Move North is outside of the if code block.
  • iv. Run and observe before proceeding to the next section.

3. Create Program P06 -- Section 3 -- Woodchuck 🌳
  • i. Append another if statement and code block to the previous to harvest Wood. Check if harvest is possible, run a code block that harvests, print the result of a planting of a Bush, or else prints the result of harvest possibility function. Regardless of if or else outcomes, move north.
  • ii. Hint -- if and else statements, [ i ] ➡️ Programming ➡️ If.
  • iii. Run and observe before proceeding to the next section.
  • iv. Observe that some crops have to be replanted or the field will revert back to Grassland.

4. Create Program P06 -- Section 4 -- Woodchuck Chuck 🌳
  • i. Append a final if statement and code block. Create an if statement that checks if harvest is possible, prints a 1, harvests, plants Bush, or else prints a 0. Regardless of if or else outcomes, move north.
  • ii. Hint -- like the previous section.
  • iii. State if can_harvest(). If code block -- input 1 into print(), harvest(), input Entities.Bush into plant(), else input 0 into print() -- end code block. move(North).

5. When reaping goals are met stop and unlock Operators tech, triggering Operators popup.
6. Furthermore unlock Senses tech, triggering Senses popup.
📝 Task 07 - 🔓 Speed II, Grass II, and Expand II Tech
Goals -- Explore combining operators while loops + unlock Speed II, Grass II, and Expand II tech
Note:
📺 Evaluating compound boolean expressions | Intro to CS - Python | Khan Academy https://youtu.be/p7pJMvD2sag?si=lklqRtUcQbHjqsCC
📺 % WHAT IS MODULO? - Python GCSE (Beginner) | @sullivan-tutor-academy https://youtube.com/shorts/NI6Vpgb2CHE?si=wZcJceVHC1PO7CB4

* Verify Speed II tech unlock cost of 10 Wood
* Verify Expand II tech unlock cost of 20 Wood
* Verify Grass II tech unlock cost of 300 Hay
* Reaping goal is 300 Hay and 30 Wood
* infinite while loops can be exited by meeting conditions or via break.
* Crops Grounds
* Have the Operators doc handy -- [ i ] ➡️ Programming ➡️ Operators
* Have the Senses doc handy -- [ i ] ➡️ Unlocks ➡️ Senses
* Various Sensor functions are documented in Builtins -- [ i ] ➡️ Builtins
* How to stop loops early -- [ i ] ➡️ Programming ➡️ Break

Here is how the relationship between ground, plant and crop works. There is a ground (Grassland and Soil) type that hosts plant (entity--Grass and Bush) type that yields crops (items--Hay and Wood). Now you can use get_ground_type(), get_entity_type(), and num_items() functions to check for ground and plant type and item quantity. Using the modulo (%) operator we can check for even or odd numbers.

1. Create Program P07 -- Section 1 -- Practice: Mathing
  • i. Hint -- Operators doc and guess the answers before you run these.
  • ii. print((2 * 2)/2 - 2 + 2)
  • iii. print(3**3)
  • iv. print(3//2)
  • v. print(4%2) #even numbers ➡️ remainders == 0
  • vi. print(5%2) #odd numbers ➡️ remainders > 0
  • vii. Run and observe -- end the section with a clear() and do_a_flip()

2. Create Program P07 -- Section 2 -- Practice: Comparing
  • i. Hint -- Operators doc and guess the answers before you run these.
  • ii. print(1 > 0)
  • iii. print(0 == 1)
  • iv. print(Entities.Grass != Entities.Grass)
  • v. print (not False)
  • vi. print(True and False)
  • vii. print(True or False)
  • viii. Run and observe -- end the section with a clear() and do_a_flip().

3. Create Program P07 -- Section 3 -- Practice: Sensory Functions
  • i. Hint -- Senses doc and Builtins for get…() functions.
  • ii. Combine the sensory capabilities with operators to satisfy two if statements and code blocks. If the sensor function finds that entity type is not Bush, run code block. If code block -- get harvest target number by adding 30 to the quantity of Hay in inventory, print it, move South.
  • iii. Second if statement -- if the sensor function finds that ground type is Grassland, run code block. If code block -- get harvest target number by adding 30 to the quantity of Wood in inventory, print it, move South.
  • iv. Observe that you have Hay and Wood harvest target numbers.
  • v. Run and observe -- end the section with a clear() and do_a_flip()

4. Create Program P07 -- Section 4 -- Sowing
Try to recreate the illustrated field below without looking at the answers below. Furthermore try to meet the reaping goals without seeing the answers below:
🌳
🌾
🌳
  • i. Let us dedicate two square plots for Bush, and one for Grass. Define a while loop with if and elif that will break out the loop or else plant a Bush on two even number, y-axis square plots.
  • ii. Hint -- see Section 1 examples (%) to check even y-axis numbers. Use sensory functions to trigger a Break ([ i ] ➡️ Programming ➡️ Break) condition.
  • iii. Observe we prevented an infinite loop.

5. Create Program P07 -- Section 5 -- Reaping
  • i. Define a while loop to meet reaping goals from section Section 3. Use if for Bush and else statement for Grass harvesting.
  • ii. Hint -- use sensors to detect Bush check the Sensors doc and functions in Builtins
  • Iii. Observe we prevented an infinite loop, again -- we are on a streak! 🌈🦄

6. Unlock Speed II, Grass II, and Expand II tech, triggering Expand 2 popup.
📝 Task 08 - 🔓 Carrot and Grass III Tech
Goals -- Explore for loops + unlock Carrot and Grass III tech

📺 For loops in Python are easy 🔁 | Fundraiser Bro Code -- https://youtu.be/KWgYha0clzw?si=hSQHRRTx3FbwmKIL
* Verify 🥕 Carrots tech unlock cost of 100 Wood.
* Verify Grass III tech unlock cost of 450 Hay.
* We need lots of practice time.
* Create red dot on the left margin to put pause [||] points
* Have the Expand II doc handy -- [ i ] ➡️ Unlocks ➡️ Expand 2

Two new tools unlocked are crucial and likely to be used every section from now. Have Expand II docs hand and practice using get_world_size() and for loops.

1. Create and run a Program P08
Program P08 -- Section 1 -- measure and travel the world
  • i. Print the world size function -- what was your guess?
  • ii. Print the world size function multiplied by two.
  • iii. According to Expand II document -- "... range(n) creates a range of numbers from 0 to n-1 …” and thus the parameter of 5 will loop 5 times, the counter will track loop 0, 1, 2, 3, and 4. Define a for loop that uses “counter” and not “i” as a counter, prints counter, then moves North, five times.
  • iv. Define a for loop that uses “counter” and not “i” as a counter, the parameter for the for loop is the result of the world size function minus one.
  • v. Observe that the for loop function can take in functions and operators as parameters.
  • vi. Run the program then reset -- clear the field, perform a flip then proceed to the next section.

Program P08 -- Section 2 -- for iffy loops
  • i. Define a for loop with a parameter of the world size function plus 2 with a code block with if, elif and else statement. For loop code block -- print the counter, check if counter is 1 then move East, or else if counter is greater than 2 then perform a flip and break out of loop, or else harvest and move North.
  • ii. Observe that the break condition is met when the counter is at 3.
  • iv. Run the program then reset -- clear the field, perform a flip then proceed to the next section.

Program 08 -- Section 3 -- every square
  • i. Define the first for loop to traverse a column, print y-position (only) and move North, length of the farm.
  • ii. Define the second for loop to traverse a row, print x-position (only) and move East, length of the farm.
  • iii. First clear the field. Create a nest by putting the y-axis for loop into the x-axis for loop, moving N-N-N-E, length of the farm (three times). Outer x-axis for loop code block -- run inner y-axis for loop and move East. Inner y-axis for loop code block -- print both x-position and y-position, move North. Use x_counter and y_counter for loop counters.
  • iv. Run the program then reset -- clear the field, perform a flip then proceed to the next section.

Program 08 -- Section 4 -- Sowing
Try to recreate the illustrated field below without looking at the answers below. Furthermore try to meet the reaping goals without seeing the answers below:
Requirements: use for loops only -- no while loops and use position with modulo operator.
🌳🌾🌳
🌳🌾🌳
🌳🌾🌳

i. Define a nested for loop to traverse all square plots of the farm. Plant bush on even columns, reservering one column for grass.
ii. Hint -- modulo operator, even numbers have 0 remainder, [ i ] ➡️ Programming ➡️ Operators

Program 08 -- Section 5 -- harvest
  • i. Calculate reaping goals by printing Hay in inventory plus 450 and Wood in inventory plus 100.
  • ii. The harvesting should be done with a while loop since it requires a large, hard to calculate number of loops. However we are going practice for loops, one more time.
  • iii. Define a nested for loop to traverse every square plot. The x-axis outer for loop will loop for 999 times. Outer x-axis for loop code block -- inner y-axis for loop that loops the farm length number, check if both Hay and Wood inventory are greater than reaping goals then breakout of loop, finally regardless of if statement result, move East. Inner y-axis for loop code block -- check if bush is present, then check harvest possibility, then harvest and replant Bush, or else check harvest possibility, then harvest, regardless if statement outcomes, move North
2. After meeting harvesting goals of 450 Hay and 100 Wood, unlock Carrot and Grass III tech, triggering the Carrot popup.
📝 Task 09 - 🔓 Speed IV, Grass IV, Expand IV, Carrot II, Tree, Variables and Function Tech.
Goals -- Explore Carrot tech + unlock Speed IV, Grass IV, Expand IV, Carrot II, Tree, Variables and Function tech.

* Verify these tech unlock costs:
Speed IV 50 Hay 30 Wood
Grass IV 675 Hay
Expand IV 50 Hay 20 Carrot
Carrot II 300 Wood
🌲 Tree 50 Wood 70 Carrot
Variables 70 Carrot
Function 80 Carrot
=================================
775 Hay, 380 Wood, 240 Carrot
* Have the Carrots doc handy -- [ i ] ➡️ Unlocks ➡️ Carrots
* Verify Carrot sowing cost is 1 Wood and 1 Hay -- [ i ] ➡️ Entities ➡️ Carrots

There is only Carrot tech we have to explore in this Task. Remember that Carrot requires tilled soil and seeds have costs. We will have double the space for Bush compared to Grass to maintain a steady reaping to supply the carrot planting costs. We are no longer over harvesting, and harvest goals are the exact unlock costs.

1. Create Program P09
Try to recreate the illustrated field below without looking at the answers below. Furthermore try to meet the reaping goals without seeing the answers below:
Requirements: use x and y positions and not modulo operator.
🥕🌳🌾
🥕🌳🌳
🥕🌳🌾

Program 09 -- Section 1 -- Sowing
  • Clear the field. Create a nested for loop to traverse the entire field, use x_counter and y_counter. The inner loop shall have three if statements. If the x-position equals 0, then till and plant Carrot, or else if the x-position equals 1, then plant Bush, or else if x-position equals 2 and y-position equals 1, then plant Bush.

Program 09 -- Section 2 -- Reaping
  • Define a while loop that will remain true until reaping goals of 775 Hay 380 Wood 240 Carrot are met. While loop code block -- a nested for loop to traverse the whole field, using x_counter and y_counter, inside. The inner for loop code block has three if statements, one for each plant type: Carrot, Bush and Grass.
2. After meeting harvesting goals of 775 Hay 380 Wood 240 Carrot, unlock Speed IV, Grass IV, Expand IV, Carrot II, Tree, Watering, and Variables tech, triggering the Carrot popup.
📝 Task 10 - 🔓 Speed V, Grass V, Carrots III, Watering, Pumpkin, and Lists Tech.
Goals -- Explore variables, tuples + unlock Speed V, Grass V, Carrots III, Watering, Pumpkin, and Lists tech.

📺 Coding Basics: Variables | Programming for Beginners | Transcode https://youtu.be/ghCbURMWBD8?si=WEfD2m3nSP3SWRJ2

* Declare variables with a single equal sign
* Verify these tech unlock costs:
Speed V -- 100 Wood 70 Carrot
Grass V -- 1010 Hay
Carrots III -- 480 Wood
Watering -- 50 Wood
Pumpkin -- 500 Wood 350 Carrot
=================================
1010 Hay, 1130 Wood, 420 Carrot

* Have the Variables doc handy -- [ i ] ➡️ Programming ➡️ Variables and [ i ] ➡️ Programming ➡️ Scope
* Have the Function doc handy -- [ i ] ➡️ Programming ➡️ Function
* Have the Tuples doc handy -- [ i ] ➡️ Programming ➡️ Tuples
* Have the Trees doc handy -- [ i ] ➡️ Unlocks ➡️ Trees and [ i ] ➡️ Entities ➡️ Trees

We will do lots of practice in the Task.

Create Program P10

Input reaping goals as tuples

1. Section 1 -- Practice variable declaration and reassignments.
  • i. Hint -- Keep the Variable doc handy and guess the result before running.
  • ii. Declare a length variable that is “... size of the farm ...”
  • iii. Declare a dogecoin variable, assign it 1.
  • iv. Reassign dogecoin as dogecoin plus one.
  • v. Repeat previous reassign but in short form, +=.
  • vi. Print the length and dogecoin
  • vii. Reassign dogecoin to 1 million.
  • viii. Print the length and dogecoin, again.
  • ix. Perform a flip to end section

2. Section 2 -- Create a for loop-like with a while loop
  • i. Hint -- Again, keep the Variable doc handy.
  • ii. Declare two variables for the while loop “end” variable to state goal number and “counter” to track loops as they are being performed.
  • iii. Define a while loop that when the counter is greater than end, runs this code block -- move east, harvest then increment counter plus one.
  • iii. Perform a flip an to end section

3. Section 3 -- Create a Section Ender function -- SecEnd()
  • i. Define a function named SecEnd that runs a code block -- perform a flip.
  • ii. Run SecEnd() and observe the result. Use this function to end sections.
  • iii. I sometimes end sections with clear() and a flip. Modify SecEnd Create a function that can clear and perform a flip but by default it should not run clear(). Redefine the SecEnd function to have a default parameter of “need” is False. The code block will start with if “need” then code block -- clear(). Finally perform a flip regardless of if outcomes.
  • iv. Run SecEnd() then move(East) and run SecEnd(True) -- observe the difference.

4. Section 4 -- Using global variables in functions
  • i. Define a function called MoneyMaker. The code block-- declare a variable called pepe and assign it 999999999. Declare that dogecoin is a global variable, then reassign dogecoin as 1, and perform a flip.
  • ii. Run MoneyMaker().
  • iii. Attempt to print pepe -- error because local variable cannot be accessed from the outside.
  • iv. Print dogecoin -- because it was declared as a global variable, the changes made inside a function were followed outside of the function.

5. Section 5 -- Another example of function creation
  • i. Define a function called mover that will take two parameters: squares and dir, runs a code block -- a for loop that takes squares as a parameter, runs code block -- moves in the direction of the parameter dir.
  • ii. Run mover(3, East) and observe the result. End the section with SecEnd(True)

6. Section 6 -- Tuples
  • i. Define a tuple called fibonacci and fill in five numbers in the fibonacci sequence: 0, 1, 1, 2, 3.
  • ii. Print the fourth and fifth element of the fibonacci tuple. Hint -- computers count elements from zero and not one.
  • iii. As stated in the beginning of the task, our reaping goals are 1010 Hay, 1130 Wood, Carrot 420 Carrot. Define a tuple called reap with elements: 1010, 1130, 420. Print reap tuple.
  • iv. Declare variables hay_goal, wood_goal, and carrot_goal and assign them first, second and third element of the reap tuple. Print hay_goal, wood_goal, and carrot_goal.
  • v. Run SecEnd function

7. Section 7 -- Sowing
🥕🌲🥕🌲
🌲🌾🌲🌾
🥕🌲🥕🌲
🌲🌾🌲🌾
  • i. Attempt to recreate that field.
  • ii. Hint -- use modulo operator to find odd and even x and y position numbers -- 🌲(x-even, y-even), 🌲(x-odd, y-odd), 🥕(x-even, y-odd).
  • iii. Continue to the reap section without clearing the field.

8. Section 8 -- Reaping
  • i. Define function that while item inventories are less than hay_goal, wood_goal, and carrot_goal run code block -- the code block should have a for loop to traverse the whole field and use three if statements: if, elif, and elif to harvest and replant (except for grass).
9. Unlock Speed V, Grass V, Carrots III, Watering, and Pumpkin. Watering, and Pumpkin will trigger Watering and Pumpkins popup.
🌵⏪ Final Project + Restart
Final Project -- 🌵🕶️ Cactus Cooler

Sorting data is a common task that pro programmer perform. Create a program to bubble sort data in the following coding challenge. Bubble sort is required for Cactus harvesting.

Python Coding Problem: Bubble Sort the Numbers 1–9
Problem Statement:
Write a Python function called bubble_sort that takes a list of integers containing the numbers 1 through 9 in any random order and returns a new list with the numbers sorted in ascending order using the bubble sort algorithm.

Requirements:
Do not use Python’s built-in sort() or sorted() functions.
Implement the bubble sort algorithm explicitly.
The function should return a new sorted list, not modify the input list in place.

Example:
# Example input numbers = [5, 9, 3, 1, 8, 6, 4, 2, 7] # Function call sorted_numbers = bubble_sort(numbers) # Expected output print(sorted_numbers) # Output: [1, 2, 3, 4, 5, 6, 7, 8, 9]

Bonus:
Count and return the number of swaps performed during the sorting process, along with the sorted list.

Example Bonus Output::
sorted_numbers, swap_count = bubble_sort(numbers) print(sorted_numbers) # [1, 2, 3, 4, 5, 6, 7, 8, 9] print(swap_count) # e.g., 18

Hint:
📺 Visualization of Bubble Sort | G Bhat
https://youtu.be/0BkoXZBbhfU?si=38eLIN8EvYrm7NkA

-----------------
🌵 Project Task
  1. Attempt to solve it in Python Online Compiler - Code Editor[www.programiz.com]
  2. Go to an large language model AI prompt, e.g. Open AI, Copilot, Gemini, Llama, Grok...
  3. input "solve the following problem and comment line by line" and the Copy, paste and enter the entire problem, with examples into the prompt.
  4. : input --
    Solve the following problem and comment line by line. Python Coding Problem: Bubble Sort the Numbers 1–9 Write a Python function called bubble_sort that takes a list of integers containing the numbers 1 through 9 in any random order and returns a new list with the numbers sorted in ascending order using the bubble sort algorithm.

  5. Observe and learn from the comments.
  6. Reproduce the answer in the Python Online Compiler - Code Editor[www.programiz.com]
If you need a basic guide on AI prompting grab 🤖 Tina Huang's AI Prompting Guide[offers.hubspot.com]


⏹️⏪▶️
Restart the game using instructions and hints only.
🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️
⚜️ Part III: Answer Key

If you really, really want to absorb this material, apply the Feynman technique and make a walkthrough guide like mine.
https://www.youtube.com/watch?v=q-16DPh_VWw
⌨️ Programs -- P01 - P05
# -------------------------- #📝 Task 01 -- Program P01 # <-- the computer ignores what is behind the # #flips gives time for grass to regrow, ready for harvest #reaping goal 5 Hay harvest() harvest() harvest() harvest() harvest() #--- [||] PAUSE --- [|>] Run the program then proceed. harvest() do_a_flip() harvest() do_a_flip() harvest() do_a_flip() harvest() do_a_flip() harvest() # -------------------------- #📝 Task 02 -- Program P02 #flips give time for grass to grow back #reaping goal 20 Hay while(False): do_a_flip() while(True): harvest() # ------------------------- #📝 Task 03 -- Program P03 #if statement and can_harvest() replaces do_a_flip() #reaping goal 30 Hay while(True): if can_harvest(): harvest() # ------------------------- #📝 Task 04 -- Program P04 -- The Haymaker #you wrap back when going over the edge #reaping goal 50 Hay while(True): if can_harvest(): harvest() move(South) # ------------------------- #📝 Task 05 Program P05 ∞ Wood #reaping goal 100 Hay (via P04) and 100 Wood while(True): if can_harvest(): harvest() plant(Entities.Bush) move(North)
⌨️ Programs -- P06 - P08
#📝 Task 06 -- Program P06 ∞ Hay and Wood Maker # Unlock costs -- Operators -- 300 Hay and 30 Wood + Senses -- 200 Hay #reaping goal -- 500 Hay + 30 Wood #click on the left margin of this window to create pause points #Section 1 -- Burrrrr print(0, 7734) clear() #--- [||] PAUSE --- [|>] Run the program then proceed. #Section 2 -- Hay is for horses while(True): if can_harvest(): harvest() move(North) #--- [||] PAUSE --- [|>] Run the program then proceed. #Section 3 -- Woodchuck if can_harvest(): harvest() print(plant(Entities.Bush)) else: print(can_harvest()) move(North) #--- [||] PAUSE --- [|>] Run the program then proceed. #Section 4 -- Woodchuck Chuck if can_harvest(): print(1) harvest() plant(Entities.Bush) else: print(0) move(North) #------------------------- #📝 Task 07 -- Program P07 #combine print(), Operators and Senses #reaping goal is 300 Hay and 30 Wood #Arithmetic Operators print((2 * 2)/2 - 2 + 2) #== 0 print(3**3) #== 9 print(3//2) #1.5 floored == 1 print(4%2) #even numbers -- remainders == 0 print(5%2) #odd numbers -- remainders > 0 do_a_flip() #--- [||] PAUSE --- [|>] Run the program then proceed #Comparison Operators print(1 > 0) #True print(0 == 1) #False print(Entities.Grass != Entities.Grass) #False print (not False) #True print(True and False) #False print(True or False) #True clear() do_a_flip() #--- [||] PAUSE --- [|>] Run the program then proceed #Senses - [ i ] --> Builtins #figure out reaping goal -- inventory + 300 Hay and 30 Wood if get_entity_type() != Entities.Bush: print(num_items(Items.Hay) + 300) #target Hay number move(South) if get_ground_type() == Grounds.Grassland: print(num_items(Items.wood) + 30) #target Wood number move(South) clear() do_a_flip() #--- [||] PAUSE --- [|>] Run the program then proceed #Field Setup #plant Bush in even numbers, 0 and 2 while(True): print(get_pos_y(), ((get_pos_y()) % 2 == 0)) if get_entity_type() == Entities.Bush: break elif ((get_pos_y()) % 2 == 0): plant(Entities.Bush) move(North) #--- [||] PAUSE --- [|>] Run the program then proceed #Reaping while(num_items(Items.Hay) < 500 or num_items(Items.wood) < 50): if can_harvest(): if get_entity_type() == Entities.Bush: harvest() plant(Entities.Bush) else: harvest() move(North) # ------------------------- #📝 Task 08 -- Program P08 #exploring for loops #for loop -- "... range(n) creates a range of numbers from 0 to n-1 which has n elements in it. #section 1 -- measure and travel the world #get_world_size() == "side length of your farm" == 3 print(get_world_size()) print(get_world_size() * 2) #for loop -- "... range(n) creates a range of numbers from 0 to n-1 which has n elements in it. #inputting a parameter of 5 will loop 5 times, the counter will track loop 0, 1, 2, 3, and 4. #the counter variable traditionally is i for counter in range(5): print(counter) move(North) for counter in range(get_world_size() - 1): print(counter) do_a_flip() clear() do_a_flip() #--- [||] PAUSE --- [|>] Run the program then proceed. #section 2 -- for iffy loops for counter in range(get_world_size() + 100): print(counter) if counter == 1: move(East) elif counter > 2: do_a_flip() break else: harvest() move(North) clear() do_a_flip() #--- [||] PAUSE --- [|>] Run the program then proceed. #section 3 -- every square #y-axis travel for y_counter in range(get_world_size()): print(get_pos_y()) move(North) #x-axis travel for x_counter in range(get_world_size()): print(get_pos_x()) move(East) clear() for x_counter in range(get_world_size()): for y_counter in range(get_world_size()): print(get_pos_x(), get_pos_y()) move(North) move(East) clear() do_a_flip() #--- [||] PAUSE --- [|>] Run the program then proceed. #section 4 -- Sowing for x_counter in range(get_world_size()): for y_counter in range(get_world_size()): if (get_pos_x() % 2 == 0): plant(Entities.Bush) move(North) move(East) #🛑 do not clear do_a_flip() #--- [||] PAUSE --- [|>] Run the program then proceed. #section 5 -- Reaping #calculate reaping goals print(num_items(Items.Hay) + 450, num_items(Items.Wood) + 100) for x_counter in range(999): for y_counter in range(get_world_size()): if get_entity_type() == Entities.Bush: if can_harvest():get harvest() plant(Entities.Bush) else: if can_harvest(): harvest() move(North) if ( (num_items(Items.Hay) > 500) and (num_items(Items.Wood) > 500) ): break move(East)
⌨️ Programs -- P09 - P10
#📝 Task 09 -- program P09 #Sowing clear() #sowing for x_counter in range(get_world_size()): for y_counter in range(get_world_size()): #run code block if get_pos_x() == 0: till() plant(Entities.Carrot) elif get_pos_x() == 1: plant(Entities.Bush) elif get_pos_x() == 2 and get_pos_y() == 1: plant(Entities.Bush) move(North) #run code block move(East) #reaping #reaping goals 775 Hay 380 Wood 240 Carrot while( (num_items(Items.Hay) < 775) or (num_items(Items.Wood) < 380) or (num_items(Items.Carrot) < 240) ): for x_counter in range(get_world_size()): for y_counter in range(get_world_size()): if get_entity_type() == Entities.Carrot: if can_harvest(): harvest() plant(Entities.Carrot) elif get_entity_type() == Entities.Bush: if can_harvest(): harvest() plant(Entities.Bush) else: if can_harvest(): harvest() move(North) move(East) # ------------------------- #📝 Task 10 -- Program P10 #create a for loop with while loop #assign variable to functions #Function tech unlock costs 40 Carrots #Section 1 -- Incrementing Variables length = get_world_size() dogecoin = 1 dogecoin = dogecoin + 1 dogecoin += 1 print(length, dogecoin) #reset counter to 1 dogecoin = 100000000 print(length, dogecoin) do_a_flip() #--- [||] PAUSE --- [|>] Run the program then proceed. #Section 2 -- Make a For Loop-Like end = 3 counter = 0 while (counter < end): move(East) harvest() counter += 1 clear() do_a_flip() #--- [||] PAUSE --- [|>] Run the program then proceed. #Section 3 -- Functions Intro #My sections end with a a flip def SecEnd(): do_a_flip() SecEnd() #many times I prefer clear and flip #the default is False and no clear def SecEnd(need = False): if need: clear() do_a_flip() SecEnd() move(East) SecEnd(True) #--- [||] PAUSE --- [|>] Run the program then proceed. #Section 4 -- global vs local scope def MoneyMaker(): pepe = 999999999 #declare that dogecoin is global variable global dogecoin #reassign dogecoin as 1 dogecoin = 1 do_a_flip() #fun function to make changes MoneyMaker() #pritingin pepe will return an error #print(pepe) print(dogecoin) #--- [||] PAUSE --- [|>] Run the program then proceed. #Section 5 -- another example #make a movement function that takes distance and direction def mover(squares, dir): for counter in range(squares): move(dir) mover(3, East) SecEnd(True) #--- [||] PAUSE --- [|>] Run the program then proceed. #Section 6 -- Tuples fibonacci = 0, 1, 1, 2, 3 print(fibonacci[3], fibonacci[4]) #reaping goals: 1010 Hay, 1130 Wood, Carrot 420 Carrot reap = 1010, 1130, 420 print(reap) hay_goal = reap[0] wood_goal = reap[1] carrot_goal = reap[2] print(carrot_goal, wood_goal, hay_goal) SecEnd() #--- [||] PAUSE --- [|>] Run the program then proceed. #Section 7 -- Sowing for x_counter in range(length): for y_counter in range(length): #(x-even, y-even) if get_pos_x() % 2 == 0 and get_pos_y() % 2 == 0: plant(Entities.Tree) #(x-odd, y-odd) elif get_pos_x() % 2 > 0 and get_pos_y() % 2 > 0: plant(Entities.Tree) #(x-even, y-odd) elif get_pos_x() % 2 == 0 and get_pos_y() % 2 > 0: till() plant(Entities.Carrot) move(North) move(East) #--- [||] PAUSE --- [|>] Run the program then proceed. #Section 8 -- Reaping while( num_items(Items.Hay) < hay_goal or num_items(Items.Wood) < wood_goal or num_items(Items.Carrot) < carrot_goal ): for x_counter in range(length): for y_counter in range(length): if get_entity_type() == Entities.Tree: if can_harvest(): harvest() plant(Entities.Tree) elif get_entity_type() == Entities.Carrot: if can_harvest(): harvest() plant(Entities.Carrot) elif get_entity_type() == Entities.Grass: if can_harvest(): harvest() move(North) move(East)
3 Comments
chaosbreaker  [author] 27 Aug @ 11:30am 
Thank you CodeAkula for noticing the effort!
CodeAkula 18 Aug @ 4:03am 
This is a super awesome guide. Personally, I program a lot in C# in unity so it was mainly syntax I was struggling with but this covered the basics and got me going in the right direction. I appreciate the effort you put in :steamthumbsup:
chaosbreaker  [author] 16 May @ 9:46am 
Workbook 1.0 shipped!