编程农场

编程农场

30 个评价
RoboCulture 101: Python for Beginners
由 chaosbreaker 制作
✨ Updated for Release 1.0 ✨

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. 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.
   
奖励
收藏
已收藏
取消收藏
🌾 🌾 🌾 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.

Initially, the tasks will provide explicit instructions. From PART II, 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 -- mobile and Flash -- demo/Flash $0
  2. One Dreamer -- Steam -- demo $0
  3. Modulo Code -- Microsoft Store -- $0
  4. May's Journey -- Steam -- $0
  5. Sam & MaRU -- Steam -- $10
📝 T01 - Hello Farm! | First Program
Task T01
Explore functions and crop growth cycle works
🔓 Goals - 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 small reusable of code appended by “()”.
* Loops unlock cost -- [ Unlocks ] ➡️ (mouse over) [ Loops ] ➡️ 5 🌾 Hay
* Read First Program -- [ i ] ➡️ General Info ➡️ First Program
* Read First Program -- [ i ] ➡️ Built-in Functions

Field -- what the field looks like before reaping -- one plot with 🌾[Grass]:
🌾

1. First Program doc shows two functions harvest() and do_a_flip() while pet_the_piggy() is under Built-in Functions
2. Create Program P01 - Hello Farm!
  • i. Prepend the harvest functions with pet_the_piggy()
  • ii. Define (type out) harvest() five times (refer to aforementioned First Program).
  • iii. Append harvest functions with do_a_flip()
3. Observe that the Hay Items (inventory) on the upper left of the screen is 5
4. Loop unlock requirements met -- unlock Loops in the tech tree -- [ Unlocks ] ➡️ (click) Loops .
5. Observe that unlocking tech can trigger an info window popup -- While Loop.

Starter code -- copy the following into the code editor:

#📝 Program P01 -- Hello Farm! #Explore built-in functions #Unlock Goal - Loops #read [ i ] ➡️ General Info ➡️ First Program #Reaping Phase #Reap 5 Hay #Write you code below #pet the pig #harvest 5 times #do a flip #Check your code with the: #🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️
📝 T02 - Mean While | Loops
📝 Task 02
Explore While loops
🔓 Goals - 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

* Unlock costs for Loops -- [ Unlocks ] ➡️ (mouse over) [ Speed ] ➡️ 20 🌾 Hay
* Read While Loop doc -- [ i ] ➡️ Unlocks ➡️ Loops

Field:
🌾

1. Refer to the While loop doc to create Program P02 Mean While
  • 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. Observe that while False code block is not triggered, no flips are performed.
  • iv. Observe that an infinite loop occurs and you only escape by terminating the program.
2. Stop program when the reaping goal of 20 Hay is met.
3. Unlock Speed in the tech tree, triggering Speed Upgrade doc popup

Starter code -- copy the following into the code editor:
#📝 Program P02 -- Mean While #Explore While Loop #Unlock Goal - Speed #Reaping Phase #Reap 20 Hay #Write your code below: #Define -- a while loop, while in False conditions, performs a flip while False: do_a_flip() #Define -- a while loop, while in True conditions, harvest while True: harvest() #Check your code with the: #🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️
📝 T03 - Iffy Lube | Speed
📝 Task 03
Explore if statements and can_harvest() function
🔓 Goals - Expand 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 Expand tech unlock cost of 30 🌾 Hay.
* Read Speed -- [ 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).

Field:
🌾

1. Create Program P03 Iffy Lube.
  • i. Define a function that if harvest is possible, harvests or else performs a flip.
  • ii. Hint -- Read the fine manual (RTFM) -- [ i ] ➡️ Unlocks ➡️ Speed
  • iii. Observe that harvesting is always successful since no premature harvest is performed.
  • iv. 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 doc popup.

Starter code -- copy the following into the code editor:
#📝 Program P03 -- Iffy Lube #Explore if statements #Unlock Goal - Expand #Reaping Phase #Reap 30 Hay #Write your code below: #Define a function that if harvest is possible, harvests or else performs a flip. #Check your code with the: #🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️
📝 T04 - On The Move | Expand
📝 Task 04
Explore the movement function
🔓 Goals - Plant tech

Note:
What is Python? Why Python is So Popular? | Programming with Mosh
https://youtu.be/Y8Tko2YC5hA?si=wI23ZwrjuEbd8g2k
* Plant tech unlock cost is 50 🌾 Hay
* Read Expand 1 doc -- [ 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 previous program, P03
2. Stop program to break the infinite loop when 50 Hay is harvested.
3. Unlock Plant tech, triggering Plant popup.

Starter code -- copy the following into the code editor:
#📝 Program P04 -- On The Move #Explore movement #Unlock Goal - Plant #you wrap back when going over the edge #Reaping Phase #Reap 30 Hay #Write code below: #while, if harvest is possible, harvest, then move South. #hint -- similar to previous program, P03 #else not needed since moving to new plot ensures harvest ready #Check your code with the: #🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️
🌲 🌲 🌲 PART II: Alea Iacta Est 🌲 🌲 🌲 🌲
⚜️ PART II -- Alea Iacta Est

You have unlocked enough techs that you can make more complex and clever programs.
📝 T05 - Bush League | Plant
📝 Task 05
Explore the Plant tech
🔓 Goals - Operators & Debug

Note:
* Operator tech unlock cost is 150 Hay and 10 Wood
* Debug tech unlock cost is 50 🌾 Hay and 50 🌳 Wood
* Read Expand 1 doc -- [ i ] ➡️ Unlocks ➡️ Plant

We now have two phases Sowing and Reaping. Sowing is for prepping the field and practice coding but will at least have clear() to reset the field while reaping is for harvesting. The programs in the Answer Keys will have these to denote phases:

#,_,_, SOWING PHASE ,_,_,_,_,_,_, #|_|_| REAPING PHASE |_|_|_|_|_|_|

Wood takes longer than Hay to grow. Therefore we will allocate two square plots for 🌳 Bush and one for 🌾 Grass.
Field:
🌾
🌳
🌳

1. Create Program P05 Bush League
  • i. Harvest then sow Bush twice, and harvest Grass once (see the Field above).
  • ii. Hint -- three separate harvests, repeated
2. Stop program when 200 Hay and 60 Wood is harvested.
3. Unlock both Operators tech and Debug triggering doc popups.

Starter code -- copy the following into the code editor:

#📝 Task 05 Program P05 -- Bush League #,_,_, SOWING PHASE ,_,_,_,_,_,_, #clear the field clear() #|_|_| REAPING PHASE |_|_|_|_|_|_| #reaping goal 100 Hay and 100 Wood #write your code below # Harvest then sow Bush twice, and harvest Grass once (see the Field above). # Hint -- three separate harvests, repeated #while loop here #1st plot -- check harvest ready #harvest #🌳 sow bush #move North to 2nd plot #2nd plot -- check harvest ready #harvest #🌳 sow bush #move North to 3rd plot #3rd plot -- check harvest ready #harvest #🌾no sowing -- keep grass #move North. wrapping around to 1st plot #Check your code with the: #🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️
📝 T06 - Press Zero For | Operators & Debug
📝 Task 06
Explore Operators & Debug
🔓 Goals - Senses
Note:
📺 Evaluating compound boolean expressions | Intro to CS - Python | Khan Academy https://youtu.be/p7pJMvD2sag?si=lklqRtUcQbHjqsCC
* Senses tech unlock costs of 100 🌾 Hay
* Have the Operators doc handy -- [ i ] ➡️ Programming ➡️ Operators
* Have the Debug doc handy -- [ i ] ➡️ Programming ➡️ Debug

1. Starter code -- Practice -- copy & paste then predict the outcome:

#📝 Task 06 -- Program P06 -- Press Zero for #Explore Operators and Debug #Unlock Goal - Senses #PRACTICE 1 -- 👨‍🏫 Modulo Operator, an Arithmetic Operator #You can check if a number is odd or even since even number do not have remainders. #even numbers have 0 remainder #odd number have >0 remainders # 👨‍🏫Print() -- you can print to the screen as a way to double check things. if 4 % 2 == 0: print("even number") else: print("odd number") move(North) if 5 % 2 == 0: print("even number") else: print("odd number") move(South) #--- [||] PAUSE --- [|>] Run the program then proceed #PRACTICE 2 -- 👨‍🏫 Comparison Operators, if 1 > 0: print(1 > 0) move(North) if 0 != 5: print(0 != 5) move(North) if 0 == 0: print(0 == 0) move(North) #--- [||] PAUSE --- [|>] Run the program then proceed #End of practice -- continue to the next section of code, Sowing and Reaping.

2. Finish up by creating the reaping phase and copy
  • i. Create code to harvest two Grass and one Bush (see above pic)
  • ii. Hint -- Bush need to be replanted.
3. 6. Unlock Senses, triggering Senses doc popup.

Add the following code to the starter code:

#Append the following code to the starter code: ,_,_, SOWING PHASE ,_,_,_,_,_,_, #PRACTICE 3 -- 👨‍🏫 Logic Operators #Observe how logic operators work. #guess which plot will grow Bush clear() if not False: plant(Entities.Bush) print("not False -->", not False) move(North) if True and False: plant(Entities.Bush) print("True and False -->", True and False) move(North) if True or False: plant(Entities.Bush) print("True or False -->", True or False) #--- [||] PAUSE --- [|>] Run the program then proceed #|_|_| REAPING PHASE |_|_|_|_|_|_| #Reap 100 Hay #The field should look like this after the Sowing Phase above : #🌾 Grass #🌳 Bush #🌾 Grass #Create a while loop to harvest then move North, harvesting Grass, Bush, then Grass. #Hint -- Bush need to be replanted. #write code below: #Check your code with the: #🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️
📝 T07 - Sensitivity Training | Sense & Debug
📝 Task 07
Explore Sense & Debug
🔓 Goals - Expand 2, Speed 2, Grass 2, Carrot, Hats, and Watering.

Note:
📺 Python Program to Check Even or Odd Number Using Modulus Operator | Python for Beginners | ProgramGuru
https://youtu.be/hZcC6R8vZYs?si=04d0EDL7Itp54DAE

* Carrot and Hat tech unlock cost is 50 🌾 Hay and 50 🌳 Wood
* infinite while loops can be exited by meeting conditions or via break.
* Read Break -- [ i ] ➡️ Programming ➡️ Break.
* Read Senses doc -- [ i ] ➡️ Unlocks ➡️ Senses
* Read Debug doc -- [ i ] ➡️ Unlocks ➡️ Debug

Starter code -- copy the following into the code editor:
#📝 Program P07 -- Sensitivity Training #Explore Senses #Unlock Goal - Carrot, Hats, Expand 2, Grass 2, Speed 2 #,_,_, SOWING PHASE ,_,_,_,_,_,_, #* We used the modulo operator, % figure out odd or even numbers in Program P06. #* Use get_pos_y() with modulo operator to plant Bush only in even numbered y-axis. #* after reaching y-axis 2, move north to y-axis 0, then break out the loop #* How to stop loops early -- [ i ] ➡️ Programming ➡️ Break #* print() your location and modulo remainders after each move to help troubleshoot #Create a while loop to create this field: #🌳 bush #🌾 grass #🌳 bush clear() #reset your field #write code to prep field for harvest below: #--- [||] PAUSE --- [|>] Run the program then proceed #|_|_| REAPING PHASE |_|_|_|_|_|_| #Reaping goal -- 350 Hay and 90 Wood # add 350 and 90 to your existing inventory to get your harvest goal print(num_items(Items.Hay) + 350, "Hay", num_items(Items.Wood) + 90, "Wood", "required" ) #verify printed goals -- [ i ] ➡️ Output ➡️ output.txt (click link to open file) #Create a while loop reap: #* identify Entities.Bush, harvest then replant bush or else harvest hay. #* If both 50 Hay and 50 Wood beyond your inventory is harvested, exit loop. #Write code below: #Check your code with the: #🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️




📝 T08 - Gone Loopy | Hats, Carrot, Expand 2 (For Loop)
Explore for loops, Hats and Carrot
🔓 Goals - Expand 3, Speed 3, Grass 3, Carrot 2, Trees, Watering, Variables

📺 For loops in Python are easy 🔁 | Fundraiser Bro Code -- https://youtu.be/KWgYha0clzw?si=hSQHRRTx3FbwmKIL

* Create red dot on the left margin to put pause [||] points
* Have the Expand II doc handy -- [ i ] ➡️ Unlocks ➡️ Expand 2

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). Use following functions to check for ground and plant type and item quantity.:
* get_ground_type()
* get_entity_type()
* num_items()


#Program P08 -- Gone Loopy #Explore Hats, Carrot, Expand 2 #Unlock Goal - Expand 3, Speed 3, Grass 3, Carrot 2, Trees, Watering, Variables #have the Output window handy -- General Info --> Output #Note planting carrot costs 1 Hay and 1 Wood, Entities --> Carrot # »»---------------► PRACTICE #reset the field clear() #get_world_size() returns the length of the field print(get_world_size(), "-- field length") move(North) print((get_world_size() + get_world_size()), "-- field length 2X") #change hats for pure esthetics change_hat(Hats.Brown_Hat) #while loop that runs while Hay inventory is less than 987654321. #observe the the increase in Hay #example using if aconditional to break out of loop while num_items(Items.Hay) < 987654321: print(num_items(Items.Hay), "- before harvest") harvest() do_a_flip() print(num_items(Items.Hay), "- after harvest") if num_items(Items.Hay) > 0: print("Break condition met--exit") break #carrots require ground prep, till() --> Grounds.Soil #entity check: check the enitity, if not Carrot, till if get_entity_type() != Entities.Carrot: print(get_entity_type()) till() #ground check: check the ground, if Soil, plant carrot if get_ground_type() == Grounds.Soil: print(get_ground_type()) plant(Entities.Carrot) #--- [||] PAUSE --- [|>] Run the program then proceed # continued below ...

➿ Let us practice using for loops.

# ... continued from above #For Loops #create a for loop named y-loop to traverse columns, y-axis #y_counter is an interger variable to count loops #y-loop - code block: print y_counter variable then move north, repeat 3 times #note - choosing range 3 will make y == 0, 1, 2 for y_counter in range(3): print("y ==", y_counter , "-- loop number", y_counter + 1) move(North) #--- [||] PAUSE --- [|>] Run the program then proceed #create a for loop named x-loop to traverse rows #use x_counter as the variable and get_world_size() for range #code block: print get_pos_x then moves east, repeat 3 times for x_counter in range(get_world_size()): print("x-axis is", x_counter ) move(East) #reset field clear() #--- [||] PAUSE --- [|>] Run the program then proceed #Traverse the entire field #Move N, N, N, and E, repeat 3 times by putting x-loop within y-loop (nesting). #x_counter and y_counter are variables and use get_world_size() for range #outer x loop code block: wear purple hat, print x position, move east #inner y loop code block: wear green hat, print y position, move north for x_counter in range(get_world_size()): for y_counter in range(get_world_size()): change_hat(Hats.Green_Hat) print(get_pos_y(), "-- y-axis, Inner loop number", y_counter + 1) move(North) change_hat(Hats.Purple_Hat) print(get_pos_x(), "-- x-axis, Outer loop number", x_counter + 1) move(East) #--- [||] PAUSE --- [|>] Run the program then proceed # continued below ...

Finally prep the field and harvest.
# ... continued from above #,_,_, SOWING PHASE ,_,_,_,_,_,_, #prep the field with a nested for loop #carrots are more needed than wood, plant carrots in column 0 and 2 #outer loop -- prints x-axis, calls an inner loop, then moves east #inner loop -- checks for x-axis, plants carrots or bush, then move north #field prep goal #🥕🌳🥕 | Carrot | Bush | Carrot | #🥕🌳🥕 | Carrot | Bush | Carrot | #🥕🌳🥕 | Carrot | Bush | Carrot | #write your code here #--- [||] PAUSE --- [|>] Run the program then proceed #|_|_| REAPING PHASE |_|_|_|_|_|_| #reaping goals 80 Wood and 125 Carrot #Expand 3 - 30 Wood 20 Carrot #Speed 3 - 50 Wood 50 Carrot #Grass 3 - 500 Wood #Carrot 2 - 250 Wood #Trees - 50 Wood 70 Carrot #Watering - 50 Wood #Variables - 35 Carrot # ====================== # 880 Wood 175 Carrot #--- [||] PAUSE --- [|>] Run the program then proceed #create a nested for loop within a while true loop. #if your Wood AND Carrot reach reaping goals, then break out of loop #write your code here #Check your code with the: #🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️
📝 T09 -- Large Order | 🔓 Trees, Watering, and Variables
Program P09 -- Large Order
Explore Trees, Watering, and Variables
Unlock Goal - Pumpkin, Fertilizer, Lists, & Functions

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

[ i ] ➡️ Unlocks ➡️ Watering
[ i ] ➡️ Built-in Functions ➡️ get_water
[ i ] ➡️ Items ➡️ Water
[ i ] ➡️ Unlocks ➡️ Trees
[ i ] ➡️ Entities ➡️ Tree
[ i ] ➡️ Entities ➡️ Operators ➡️ % Modulo Operator
[ i ] ➡️ Unlocks ➡️ Variables


Carrots require tilled soil, 2 Hay and 2 Wood. We can use variables to and seeds have costs. We are no longer over harvesting, and harvest goals are the exact unlock costs.

🌲Trees are different from 🌳 Bush, it grows best when staggered like below:
🌲🌾🌲
🌾🌲🌾
🌲🌾🌲

Program P09 -- Large Order #Explore Trees, Watering, and Variables #Unlock Goal - Pumpkin, Fertilizer, Lists, & Functions #have the Output window handy -- General Info --> Output #Note planting carrot costs 1 Hay and 1 Wood, Entities --> Carrot # »»---------------► PRACTICE #reset the field clear() # Watering # [ i ] ➡️ Unlocks ➡️ Watering # [ i ] ➡️ Built-in Functions ➡️ get_water # [ i ] ➡️ Items ➡️ Water while True: print(get_water() ) use_item(Items.Water) move(North) if get_water() > 0.25: print(get_water() ) break #--- [||] PAUSE --- [|>] Run the program then proceed clear() #variables # [ i ] ➡️ Unlocks ➡️ Variables farmside = get_world_size() #odds & evens # [ i ] ➡️ Entities ➡️ Operators ➡️ % Modulo Operator for y_counter in range( farmside ): move(North) if get_pos_y() % 2 == 0: print("even number") plant(Entities.Tree) move(East) for y_counter in range( farmside ): move(North) if get_pos_y() % 2 > 0: print("odd number") plant(Entities.Tree) #--- [||] PAUSE --- [|>] Run the program then proceed #using varibles to making a for loop max_loop = 3 loop = 0 while loop < max_loop: pet_the_piggy() #imcrement counter ➡️ reassign loop as loop number plus one loop = loop + 1 print(loop) #--- [||] PAUSE --- [|>] Run the program then proceed # continued below ⬇️ ...

Trees will take the most space since Wood is a requirement to sow Carrots.

# ... continued from above ⬆️ #,_,_, SOWING PHASE ,_,_,_,_,_,_, # Trees # [ i ] ➡️ Unlocks ➡️ Trees # [ i ] ➡️ Entities ➡️ Tree #Field prep visual map: # | 🥕C | 🌲T | 🥕C | 🌲T | # | 🌲T | 🌾G | 🌲T | 🌾G | # | 🥕C | 🌲T | 🥕C | 🌲T | # | 🌲T | 🌾G | 🌲T | 🌾G | # x, y coordinates: # | 0,3 C | 1,3 T | 2,3 C | 1,3 T | # | 0,2 T | 1,2 G | 2,2 T | 1,2 G | # | 0,1 C | 1,1 T | 2,1 C | 1,1 T | # | 0,0 T | 1,0 G | 2,0 T | 3,0 G | # Sowing Locations: #🌲 T-Tee (x-even and y-even) #🌲 T-Tree (x-odd and y-odd) #🥕 C-Carrot (x-even and y-odd) #🌾 G-Grass (x-odd and y-even) automatic -- leave alone #create a nested for loop, an x-row outer loop an y-column inner loop #define 3 if/elif statments: # checks for odd or even number with modulo operator for x,y pair # then check the x,y pair against the Sowing Locations table above for x_counter in range(farmside): for y_counter in range(farmside): #if statement for (x-even, y-even) check # your code here #if statement for(x-odd, y-odd) # your code here #if statement for(x-even, y-odd) # your code here move(North) move(East) #--- [||] PAUSE --- [|>] Run the program then proceed #|_|_| REAPING PHASE |_|_|_|_|_|_| # Speed 4 - 500 Carrot # Grass 4 - 2500 Wood # Expand 4 - 100 Wood 50 Carrot # Carrot 3 - 1250 Wood # Trees 2 - 300 Hay # Watering 2 - 200 Wood # Pumpkin - 500 Wood 200 Carrot # Fertilizer - 500 Wood # Lists - 500 Carrot # Functions - 40 Carrot #==================== # 300 Hay, 5050 Wood, & 1290 Carrot #put on your work hat, the Staw Hat #print reaping goals change_hat(Hats.Straw_Hat) hay_goal = ( num_items(Items.Hay) + 300 ) wood_goal = ( num_items(Items.Wood) + 5050 ) carrot_goal = ( num_items(Items.Wood) + 1290 ) print( "Reaping goals --", hay_goal , "Hay", wood_goal , "Wood", carrot_goal , "Carrot" ) #verify - [ i ] ➡️ Unlocks ➡️ Debug ➡️ Variables ➡️ output.txt #--- [||] PAUSE --- [|>] Run the program then proceed #Hay costs zero to produce and thus is not monitored while ( (num_items(Items.Wood) < wood_goal) or (num_items(Items.Carrot) < carrot_goal) ): # your code here move(East) #Check your code with the: #🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️
📝 Task 10 - Pumpkin Patch | Pumpkin, Lists, & Functions
Program P10 -- Pumpkin Patch
Explore - Pumpkin, Lists, & Functions
🔓 Unlock Goal - Fertilizer, Dictionaries, Import, Utilities

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

Pumpkins 🎃 require more planning. Copy the following starter code:

#Program P10 -- Pumpkin Patch #Explore - Pumpkin, Fertilizer, Lists, & Functions #Unlock Goal - Fertilizer, Dictionaries, Import, Utilities #Reaping goal -- # 1200 Hay, 22050 Wood, 1080 Carrot, & 4500 Pumpkin #Note: this field is self suffcient provifing all inputs needed for carrot 🥕 and pumpkin 🎃. # »»---------------► PRACTICE #reset the field clear() # Functions # [ i ] ➡️ Unlocks ➡️ Functions # [ i ] ➡ Programming ➡️ Name Scopes #simple function to find if a number is odd #input an intger and the function will return true or false def oddity(integer): # take arugment, interger return integer % 2 != 0 #invoke oddity function with an argument and print it print(oddity(5), "-- is odd" ) move(North) print(oddity(2), "-- is even" ) do_a_flip() #Scope #what happens when variables are delcared inside of a function #assign tip to 0.10 then reassign tip as 0.50 inside the function tip = 0.11 def tipper(number): tip = 0.55 return number * tip #invoke tipper function with an argument and print it, then print tip variable print(tipper(1000)) move(North) print(tip) do_a_flip() #observe that outside of function, variables tip is unchanged # Lists # [ i ] ➡️ Unlocks ➡️ Lists # create a list with three elements # access elements by position, index numbers 0, 1, 2 easyas = [1, 2, 3] move(North) print( easyas[0], "...", easyas[2] ) do_a_flip() # create an empty list warehouse = [] print(warehouse) move(North) # add Items.Hay, Items.Carrot, Items.Carrot, Items.Water then print warehouse # add the following to the end of the list (append): warehouse.append(Items.Hay) warehouse.append(Items.Carrot) warehouse.append(Items.Pumpkin) warehouse.append(Items.Carrot) warehouse.append(Items.Carrot) warehouse.append("multipass") warehouse.append(Items.Water) warehouse.append(Items.Water) #how many elements are in the array?? print(len(warehouse)) #print the array before we change it move(North) print(warehouse) # change the list and print each time: # remove the 5th element warehouse.pop(5) print(warehouse) move(North) # remove the last element warehouse.pop() print(warehouse) move(North) # remove the first occurance of Carrot warehouse.remove(Items.Carrot) print(warehouse) move(North) # remove the first occurance of Carrot, again warehouse.remove(Items.Carrot) print(warehouse) move(North) # add Items.Wood at index 2 warehouse.insert(2, Items.Wood) print(warehouse) move(North) # remove first instance of pumpkin warehouse.remove(Items.Pumpkin) # print final size and content of the array print(len(warehouse), "--", warehouse) #--- [||] PAUSE --- [|>] Run the program then proceed continued ...

#,_,_, SOWING PHASE ,_,_,_,_,_,_, #Field prep map P-umpkin, T-ree, C-arrot, G-rass: # | 🌲T | 🥕C | 🌲T | 🥕C | 🌲T | 🥕C | # | 🥕C | 🌲T | 🥕C | 🌲T | 🥕C | 🌲T | # | 🎃P | 🎃P | 🎃P | 🎃P | 🌲T | 🥕C | # | 🎃P | 🎃P | 🎃P | 🎃P | 🌾G | 🌲T | # | 🎃P | 🎃P | 🎃P | 🎃P | 🌲T | 🌾G | # | 🎃P | 🎃P | 🎃P | 🎃P | 🌾G | 🌲T | # Coordinates Table: # | 0,5 | 1,5 | 2,5 | 3,5 | 4,5 | 5,5 | # | 0,4 | 1,4 | 2,4 | 3,4 | 4,4 | 5,4 | # | 0,3 | 1,3 | 2,3 | 3,3 | 4,3 | 5,3 | # | 0,2 | 1,2 | 2,2 | 3,2 | 4,3 | 5,2 | # | 0,1 | 1,1 | 2,1 | 3,1 | 4,1 | 5,1 | # | 0,0 | 1,0 | 2,0 | 3,0 | 4,0 | 5,0 | # Sowing Locations: # 1 southwest - 0,0 to 3,3 - pumpkin patch # 2 southeast - 4,0 to 5,5 - trees, grass, and carrots # 3 north - 0,4 to 5,5 - trees and carrots # Pumpkins require retangualr space, see docs: # [ i ] ➡️ Unlocks ➡️ Pumpkins # [ i ] ➡️ Entities ➡️ Pumpkin 🎃 # create a nested for loop, an x-row outer loop an y-column inner loop # define 3 if/elif statments: # checks for odd or even numbers # then check the x,y pair against the SCoordinates Table above clear() farmside = get_world_size() # x + y, if x or y is odd, the sume is aslo odd thus use modulus of x+y to find odd numbers # define odditor function that modifies the oddity function to take in two numbers as arguments then add it. def odditor(num1, num2): -- your code here -- # southwest - 0,0 to 3,3 - pumpkin patch # you need to move North more than once to wrap around for x_counter in ... for y_counter ... -- your code here -- # southeast - 4,0 to 5,5 - trees, grass, and carrots # you need to move North more than once to wrap around # exception -- carrot on plot 5,3 for x_counter in ... for y_counter ... -- your code here -- #north - 0,4 to 5,5 - trees and carrots for x_counter in ... for y_counter ... -- your code here -- #|_|_| REAPING PHASE |_|_|_|_|_|_| # Speed 5 1000 Carrot # Grass 5 12500 Wood # Expand 5 1000 Pumpkin # Carrot 4 6250 Wood # Watering 3 800 Wood # Trees 3 1200 Hay # Fertilizer 2 1500 Wood # Dictionaries 2500 Pumpkin # Import 80 Carrot # Utilities 1000 Pumpkin #==================== # 1200 Hay, 22050 Wood, 1080 Carrot, & 4500 Pumpkin #put on your work hat, the Straw Hat #print reaping goals change_hat(Hats.Straw_Hat) hay_goal = ( num_items(Items.Hay) + 1200 ) wood_goal = ( num_items(Items.Wood) + 22050 ) carrot_goal = ( num_items(Items.Wood) + 1080 ) pumpkin_goal = ( num_items(Items.Pumpkin) + 4500 ) print( "Reaping goals --", reap[0] , "Hay", reap[1] , "Wood", reap[2] , "Carrot", reap[3] , "Pumpkin" ) #verify - [ i ] ➡️ Unlocks ➡️ Debug ➡️ Variables ➡️ output.txt #--- [||] PAUSE --- [|>] Run the program then proceed # Hay costs zero to produce and thus is not monitored # dead pumpkins -- sow pumpkin, cannot harvest # harvesting a pumpkin larger than one plot will leave multiple plots empty # Pumpkins are in x <4 and y<4 reap = [ hay_goal, wood_goal, carrot_goal, pumpkin_goal ] while ( num_items(Items.Wood) < reap[1] or num_items(Items.Carrot) < reap[2] or num_items(Items.Wood) < reap[3] ): for x_counter in range(farmside): for y_counter in range(farmside): #Wood reaping -- your code here -- #Carrot reaping -- your code here -- #pumpkin reaping #deap pumpkin - sow -- your code here -- #Hay reaping move(East)
🌵Cactus Cooler -- Final Project
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
💾Program P01 -- Hello Farm!
#📝 Program P01 -- Hello Farm! #Explore built-in functions #Unlock Goal - Loops #read [ i ] ➡️ General Info ➡️ First Program #Reaping Phase #Reap 5 Hay #Write you code below #pet the pig pet_the_piggy() #harvest 5 times harvest() harvest() harvest() harvest() harvest() #do a flip do_a_flip()
💾Program P02 -- Mean While
#📝 Program P02 -- Mean While #Explore While Loop #Unlock Goal - Speed #Reaping Phase #Reap 20 Hay #Write your code below: #Define -- a while loop, while in False conditions, performs a flip while False: do_a_flip() #Define -- a while loop, while in True conditions, harvest while True: harvest()
💾Program P03 -- Iffy Lube
#📝 Program P03 -- Iffy Lube #Explore if statements #Unlock Goal - Expand #Reaping Phase #Reap 30 Hay #Write your code below: #Define a function that if harvest is possible, harvests or else performs a flip. while True: if can_harvest(): harvest() else: do_a_flip()
💾Program P04 -- On The Move
#📝 Program P04 -- On The Move #Explore movement #Unlock Goal - Plant #you wrap back when going over the edge #Reaping Phase #Reap 30 Hay #Write code below: #while, if harvest is possible, harvest, then move South. #hint -- similar to previous program, P03 #else not needed since moving to new plot ensures harvest ready while True: if can_harvest(): harvest() move(South)
💾Program P05 -- Bush League
#📝 Task 05 Program P05 -- Bush League #,_,_, SOWING PHASE ,_,_,_,_,_,_, clear() #clear the field #|_|_| REAPING PHASE |_|_|_|_|_|_| #reaping goal 100 Hay and 100 Wood #write your code below # Harvest then sow Bush twice, and harvest Grass once (see the Field above). # Hint -- three separate harvests, repeated #while loop here while(True): if can_harvest(): harvest() plant(Entities.Bush) move(North) if can_harvest(): harvest() plant(Entities.Bush) move(North) if can_harvest(): harvest() move(North)
💾Program P06 -- Press Zero for ...
#📝 Task 06 -- Program P06 Press Zero for #Explore Operators and Debug #Unlock Goal - Senses #PRACTICE sessions #modulo operator % from Arthmetic Operators, checks for even or odd number #even numbers have 0 remainder #odd number have >0 remainders clear() if 4 % 2 == 0: print("even number") else: print("odd number") move(North) if 5 % 2 == 0: print("even number") else: print("odd number") move(South) #--- [||] PAUSE --- [|>] Run the program then proceed #observe how comparison operators work if 1 > 0: print(1 > 0) move(North) if 0 != 5: print(0 != 5) move(North) if 0 == 0: print(0 == 0) move(North) #--- [||] PAUSE --- [|>] Run the program then pr #,_,_, SOWING PHASE ,_,_,_,_,_,_, #observe how logic operators work #guess which plot will grow Bush clear() if not False: plant(Entities.Bush) print("not False -->", not False) move(North) if True and False: plant(Entities.Bush) print("True and False -->", True and False) move(North) if True or False: plant(Entities.Bush) print("True or False -->", True or False) #--- [||] PAUSE --- [|>] Run the program then proceed #|_|_| REAPING PHASE |_|_|_|_|_|_| #Reap 100 Hay while True: if can_harvest(): harvest() move(North) if can_harvest(): harvest() plant(Entities.Bush) move(North) if can_harvest(): harvest() move(North)
💾Program P07 -- Sensitivity Training
#Task 07 -- Program P07 -- So Sensitive #Explore Senses #Unlock Goal - Carrot, Hats, Expand 2, Grass 2, Speed 2 #,_,_, SOWING PHASE ,_,_,_,_,_,_, clear() #inventory check while get_pos_y() < 3: print(get_pos_y(), "y-axis", (get_pos_y() % 2), "remainder") if (get_pos_y() % 2) == 0: plant(Entities.Bush) if get_pos_y() == 2: move(North) break else: move(North) #--- [||] PAUSE --- [|>] Run the program then proceed #|_|_| REAPING PHASE |_|_|_|_|_|_| #Reaping goal -- 350 Hay and 90 Wood print(num_items(Items.Hay) + 350, "Hay", num_items(Items.Wood) + 90, "Wood", "required" ) while True: if can_harvest(): if get_entity_type() == Entities.Bush: harvest() plant(Entities.Bush) else: harvest() if (num_items(Items.Hay) > 550) and (num_items(Items.Wood) > 190): break move(North)
💾Program P08 -- Gone Loopy
#Program P08 -- Gone Loopy
#Explore Hats, Carrot, Expand 2
#Unlock Goal - Expand 3, Trees, Variables
#have the Output window handy -- General Info --> Output
#Note planting carrot costs 1 Hay and 1 Wood, Entities --> Carrot

# »»---------------► PRACTICE
#reset the field
clear()

#get_world_size() returns the length of the field
print(get_world_size(), "-- field length")
move(North)
print((get_world_size() + get_world_size()), "-- field length 2X")

#change hats for pure esthetics
change_hat(Hats.Brown_Hat)

#while loop that runs while Hay inventory is less than 987654321.
#observe the the increase in Hay
#example using if aconditional to break out of loop

while num_items(Items.Hay) < 987654321:
print(num_items(Items.Hay), "- before harvest")
harvest()
do_a_flip()
print(num_items(Items.Hay), "- after harvest")
if num_items(Items.Hay) > 0:
print("Break condition met--exit")
break

#carrots require ground prep, till() --> Grounds.Soil
#entity check: check the enitity, if not Carrot, till
if get_entity_type() != Entities.Carrot:
print(get_entity_type())
till()

#ground check: check the ground, if Soil, plant carrot
if get_ground_type() == Grounds.Soil:
print(get_ground_type())
plant(Entities.Carrot)

#--- [||] PAUSE --- [|>] Run the program then proceed

# for loops

#create a for loop named y-loop to traverse columns, y-axis
#y_counter is an interger variable to count loops
#y-loop - code block: print y_counter variable then move north, repeat 3 times
#note - choosing range 3 will make y == 0, 1, 2

for y_counter in range(3):
print("y ==", y_counter , "-- loop number", y_counter + 1)
move(North)

#--- [||] PAUSE --- [|>] Run the program then proceed

#create a for loop named x-loop to traverse rows
#use x_counter as the variable and get_world_size() for range
#code block: print get_pos_x then moves east, repeat 3 times

for x_counter in range(get_world_size()):
print("x-axis is", x_counter )
move(East)

#reset field
clear()

#--- [||] PAUSE --- [|>] Run the program then proceed

#Traverse the entire field
#Move N, N, N, and E, repeat 3 times by putting x-loop within y-loop (nesting).
#x_counter and y_counter are variables and use get_world_size() for range
#outer x loop code block: wear purple hat, print x position, move east
#inner y loop code block: wear green hat, print y position, move north

for x_counter in range(get_world_size()):
for y_counter in range(get_world_size()):
change_hat(Hats.Green_Hat)
print(get_pos_y(), "-- y-axis, Inner loop number", y_counter + 1)
move(North)
change_hat(Hats.Purple_Hat)
print(get_pos_x(), "-- x-axis, Outer loop number", x_counter + 1)
move(East)

#--- [||] PAUSE --- [|>] Run the program then proceed

#,_,_, SOWING PHASE ,_,_,_,_,_,_,

#prep the field with a nested for loop
#carrots are mone needed than wood, plant carrots in column 0 and 2
#outer loop -- prints x-axis, calls an inner loop, then moves east
#inner loop -- checks for x-axis, plants carrots or bush, then move north

#field prep goal
#🥕🌳🥕 | Carrot | Bush | Carrot |
#🥕🌳🥕 | Carrot | Bush | Carrot |
#🥕🌳🥕 | Carrot | Bush | Carrot |

for x in range(get_world_size()):
for y in range(get_world_size()):
if get_pos_x() == 1:
plant(Entities.Bush)
else:
till()
plant(Entities.Carrot)
move(North)
move(East)

#--- [||] PAUSE --- [|>] Run the program then proceed

#|_|_| REAPING PHASE |_|_|_|_|_|_|
#reaping goals 80 Wood and 125 Carrot

#Expand 3 - 30 Wood 20 Carrot
#Speed 3 - 50 Wood 50 Carrot
#Grass 3 - 500 Wood
#Carrot 2 - 250 Wood
#Trees - 50 Wood 70 Carrot
#Watering - 50 Wood
#Variables - 35 Carrot
# ======================
# 880 Wood 175 Carrot

#put on your work hat, Staw Hat
#print reaping goals

change_hat(Hats.Straw_Hat)

print(
"Reaping goals --",
(num_items(Items.Wood) + 880), "Wood",
(num_items(Items.Carrot) + 175), "Carrot"
)

#--- [||] PAUSE --- [|>] Run the program then proceed

#create a nested for loop within a while true loop.
##if your Wood AND Carrot reach reaping goals, then break out of loop

while True:
for x_counter in range(get_world_size()):
for y_counter in range(get_world_size()):
# using continue, [ i ] ➡️ Programming ➡️ Continue
if not can_harvest():
move(North)
continue
harvest()
if get_ground_type() == Grounds.Soil:
plant(Entities.Carrot)
else:
plant(Entities.Bush)
move(North)
move(East)
if ( ( num_items(Items.Wood) > 950 ) and ( num_items(Items.Carrot) > 200) ):
break
💾Program P09 -- Large Order
#Program P09 -- Large Order #Explore Trees, Watering, and Variables #Unlock Goal - Pumpkin, Fertilizer, Lists, & Functions #have the Output window handy -- General Info --> Output #Note planting carrot costs 1 Hay and 1 Wood, Entities --> Carrot # »»---------------► PRACTICE #reset the field clear() # Watering # [ i ] ➡️ Unlocks ➡️ Watering # [ i ] ➡️ Built-in Functions ➡️ get_water # [ i ] ➡️ Items ➡️ Water while True: print(get_water() ) use_item(Items.Water) move(North) if get_water() > 0.25: print(get_water() ) break #--- [||] PAUSE --- [|>] Run the program then proceed clear() #variables # [ i ] ➡️ Unlocks ➡️ Variables farmside = get_world_size() #odds & evens # [ i ] ➡️ Entities ➡️ Operators ➡️ % Modulo Operator for y_counter in range( farmside ): move(North) if get_pos_y() % 2 == 0: print("even number") plant(Entities.Tree) move(East) for y_counter in range( farmside ): move(North) if get_pos_y() % 2 > 0: print("odd number") plant(Entities.Tree) #--- [||] PAUSE --- [|>] Run the program then proceed #using varibles to making a for loop max_loop = 3 loop = 0 while loop < max_loop: pet_the_piggy() #imcrement counter ➡️ reassign loop as loop number plus one loop = loop + 1 print(loop) #--- [||] PAUSE --- [|>] Run the program then proceed #,_,_, SOWING PHASE ,_,_,_,_,_,_, # Trees # [ i ] ➡️ Unlocks ➡️ Trees # [ i ] ➡️ Entities ➡️ Tree #Field prep map with x, y cordinates: # 🥕🌲🥕🌲 | 0,3 Carrot | 1,3 Tree__ | 2,3 Carrot | 1,3 Tree__ | # 🌲🌾🌲🌾 | 0,2 Tree__ | 1,2 Hay___ | 2,2 Tree__ | 1,2 Hay___ | # 🥕🌲🥕🌲 | 0,1 Carrot | 1,1 Tree__ | 2,1 Carrot | 1,1 Tree__ | # 🌲🌾🌲🌾 | 0,0 Tree__ | 1,0 Hay___ | 2,0 Tree__ | 3,0 Hay___ | # Sowing Locations: #🌲 Tree (x-even and y-even) #🌲 Tree (x-odd and y-odd) #🥕 Carrot (x-even and y-odd) #🌾 Hay (x-odd and y-even) automatic -- leave alone #create a nested for loop, an x-row outer loop an y-column inner loop #define 3 if/elif statments: # checks for odd or even number with modulo operator for x,y pair # then check the x,y pair against the Sowing Locations table above for x_counter in range(farmside): for y_counter in range(farmside): #(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 #|_|_| REAPING PHASE |_|_|_|_|_|_| # Speed 4 - 500 Carrot # Grass 4 - 2500 Wood # Expand 4 - 100 Wood 50 Carrot # Carrot 4 - 1250 Wood # Trees 2 - 300 Hay # Watering 2 - 200 Wood # Pumpkin - 500 Wood 200 Carrot # Fertilizer - 500 Wood # Lists - 500 Carrot # Functions - 40 Carrot #==================== # 300 Hay, 5050 Wood, & 1290 Carrot #put on your work hat, the Staw Hat #print reaping goals change_hat(Hats.Straw_Hat) hay_goal = ( num_items(Items.Hay) + 300 ) wood_goal = ( num_items(Items.Wood) + 5050 ) carrot_goal = ( num_items(Items.Wood) + 1290 ) print( "Reaping goals --", hay_goal , "Hay", wood_goal , "Wood", carrot_goal , "Carrot" ) #verify - [ i ] ➡️ Unlocks ➡️ Debug ➡️ Variables ➡️ output.txt #--- [||] PAUSE --- [|>] Run the program then proceed #Hay costs zero to produce and thus is not monitored while ( (num_items(Items.Wood) < wood_goal) or (num_items(Items.Carrot) < carrot_goal) ): for x_counter in range(farmside): for y_counter in range(farmside): #Wood reaping if get_entity_type() == Entities.Tree: #water here if get_water() < 0.25: use_item(Items.Water) if can_harvest(): harvest() plant(Entities.Tree) #Carrot reaping elif get_entity_type() == Entities.Carrot: if can_harvest(): harvest() plant(Entities.Carrot) #Hay reaping else: harvest() move(North) move(East)
💾Program P10 - Pumpkin Patch
#Program P10 -- Pumpkin Patch #Explore - Pumpkin, Fertilizer, Lists, & Functions #Unlock Goal - Fertilizer, Dictionaries, Import, Utilities #Reaping goal -- # 1200 Hay, 22050 Wood, 1080 Carrot, & 4500 Pumpkin #Note: this field is self suffcient provifing all inputs needed for carrot 🥕 and pumpkin 🎃. # »»---------------► PRACTICE #reset the field clear() # Functions # [ i ] ➡️ Unlocks ➡️ Functions # [ i ] ➡ Programming ➡️ Name Scopes #simple function to find if a number is odd #input an intger and the function will return true or false def oddity(integer): # take arugment, interger return integer % 2 != 0 #invoke oddity function with an argument and print it print(oddity(5), "-- is odd" ) move(North) print(oddity(2), "-- is even" ) do_a_flip() #Scope #what happens when variables are delcared inside of a function #assign tip to 0.10 then reassign tip as 0.50 inside the function tip = 0.11 def tipper(number): tip = 0.55 return number * tip #invoke tipper function with an argument and print it, then print tip variable print(tipper(1000)) move(North) print(tip) do_a_flip() #observe that outside of function, variables tip is unchanged # Lists # [ i ] ➡️ Unlocks ➡️ Lists # create a list with three elements # access elements by position, index numbers 0, 1, 2 easyas = [1, 2, 3] move(North) print( easyas[0], "...", easyas[2] ) do_a_flip() # create an empty list warehouse = [] print(warehouse) move(North) # add Items.Hay, Items.Carrot, Items.Carrot, Items.Water then print warehouse # add the following to the end of the list (append): warehouse.append(Items.Hay) warehouse.append(Items.Carrot) warehouse.append(Items.Pumpkin) warehouse.append(Items.Carrot) warehouse.append(Items.Carrot) warehouse.append("multipass") warehouse.append(Items.Water) warehouse.append(Items.Water) #how many elements are in the array?? print(len(warehouse)) #print the array before we change it move(North) print(warehouse) # change the list and print each time: # remove the 5th element warehouse.pop(5) print(warehouse) move(North) # remove the last element warehouse.pop() print(warehouse) move(North) # remove the first occurance of Carrot warehouse.remove(Items.Carrot) print(warehouse) move(North) # remove the first occurance of Carrot, again warehouse.remove(Items.Carrot) print(warehouse) move(North) # add Items.Wood at index 2 warehouse.insert(2, Items.Wood) print(warehouse) move(North) # remove first instance of pumpkin warehouse.remove(Items.Pumpkin) # print final size and content of the array print(len(warehouse), "--", warehouse) #--- [||] PAUSE --- [|>] Run the program then proceed #,_,_, SOWING PHASE ,_,_,_,_,_,_, #Field prep map P-umpkin, T-ree, C-arrot, G-rass: # | 🌲T | 🥕C | 🌲T | 🥕C | 🌲T | 🥕C | # | 🥕C | 🌲T | 🥕C | 🌲T | 🥕C | 🌲T | # | 🎃P | 🎃P | 🎃P | 🎃P | 🌲T | 🥕C | # | 🎃P | 🎃P | 🎃P | 🎃P | 🌾G | 🌲T | # | 🎃P | 🎃P | 🎃P | 🎃P | 🌲T | 🌾G | # | 🎃P | 🎃P | 🎃P | 🎃P | 🌾G | 🌲T | # Coordinates Table: # | 0,5 | 1,5 | 2,5 | 3,5 | 4,5 | 5,5 | # | 0,4 | 1,4 | 2,4 | 3,4 | 4,4 | 5,4 | # | 0,3 | 1,3 | 2,3 | 3,3 | 4,3 | 5,3 | # | 0,2 | 1,2 | 2,2 | 3,2 | 4,3 | 5,2 | # | 0,1 | 1,1 | 2,1 | 3,1 | 4,1 | 5,1 | # | 0,0 | 1,0 | 2,0 | 3,0 | 4,0 | 5,0 | # Sowing Locations: # 1 southwest - 0,0 to 3,3 - pumpkin patch # 2 southeast - 4,0 to 5,5 - trees, grass, and carrots # 3 north - 0,4 to 5,5 - trees and carrots # Pumpkins require retangualr space, see docs: # [ i ] ➡️ Unlocks ➡️ Pumpkins # [ i ] ➡️ Entities ➡️ Pumpkin 🎃 # create a nested for loop, an x-row outer loop an y-column inner loop # define 3 if/elif statments: # checks for odd or even numbers # then check the x,y pair against the SCoordinates Table above clear() farmside = get_world_size() # x + y, if x or y is odd, the sume is aslo odd thus use modulus of x+y to find odd numbers # define odditor function that modifies the oddity function to take in two numbers as arguments then add it. def odditor(num1, num2): return ( num1 + num2 ) % 2 != 0 # southwest - 0,0 to 3,3 - pumpkin patch # you ned to move North more than once to wrap around for x_counter in range(farmside - 2): for y_counter in range(farmside - 2): if get_ground_type() == Grounds.Grassland: till() plant(Entities.Pumpkin) harvest() plant(Entities.Pumpkin) move(North) move(East) move(North) move(North) # southeast - 4,0 to 5,5 - trees, grass, and carrots # you need to move North more than once to wrap around # exception -- carrot on plot 5,3 for x_counter in range(farmside - 4): for y_counter in range(farmside - 2): if odditor( get_pos_x(), get_pos_y() ) == True: plant(Entities.Tree) elif get_pos_x() == 5 and get_pos_y() == 3: till() plant(Entities.Carrot) move(North) move(East) if get_pos_x() == 0: break move(North) move(North) #north - 0,4 to 5,5 - trees and carrots for y_counter in range(farmside - 4): for x_counter in range(farmside): if odditor( get_pos_x(), get_pos_y() ) == True: plant(Entities.Tree) else: till() plant(Entities.Carrot) move(East) move(North) #--- [||] PAUSE --- [|>] Run the program then proceed #|_|_| REAPING PHASE |_|_|_|_|_|_| # Speed 5 1000 Carrot # Grass 5 12500 Wood # Expand 5 1000 Pumpkin # Carrot 4 6250 Wood # Watering 3 800 Wood # Trees 3 1200 Hay # Fertilizer 2 1500 Wood # Dictionaries 2500 Pumpkin # Import 80 Carrot # Utilities 1000 Pumpkin #==================== # 1200 Hay, 22050 Wood, 1080 Carrot, & 4500 Pumpkin #put on your work hat, the Straw Hat #print reaping goals change_hat(Hats.Straw_Hat) hay_goal = ( num_items(Items.Hay) + 1200 ) wood_goal = ( num_items(Items.Wood) + 22050 ) carrot_goal = ( num_items(Items.Wood) + 1080 ) pumpkin_goal = ( num_items(Items.Pumpkin) + 4500 ) print( "Reaping goals --", reap[0] , "Hay", reap[1] , "Wood", reap[2] , "Carrot", reap[3] , "Pumpkin" ) #verify - [ i ] ➡️ Unlocks ➡️ Debug ➡️ Variables ➡️ output.txt #--- [||] PAUSE --- [|>] Run the program then proceed # Hay costs zero to produce and thus is not monitored # dead pumpkins -- sow pumpkin, cannot harvest # harvesting a pumpkin larger than one plot will leave multiple plots empty # Pumpkins are in x <4 and y<4 reap = [ hay_goal, wood_goal, carrot_goal, pumpkin_goal ] while ( num_items(Items.Wood) < reap[1] or num_items(Items.Carrot) < reap[2] or num_items(Items.Wood) < reap[3] ): for x_counter in range(farmside): for y_counter in range(farmside): #Wood reaping if get_entity_type() == Entities.Tree: #water here if get_water() < 0.21: use_item(Items.Water) if can_harvest(): harvest() plant(Entities.Tree) #Carrot reaping elif get_entity_type() == Entities.Carrot: if can_harvest(): harvest() plant(Entities.Carrot) #pumpkin reaping #deap pumpkin - sow elif ( get_pos_x() < 4 and get_pos_y() < 4 ): if get_entity_type() != Entities.Pumpkin: plant(Entities.Pumpkin) if get_water() < 0.41: use_item(Items.Water) if can_harvest(): harvest() plant(Entities.Pumpkin) #Hay reaping else: harvest() move(North) move(East)
5 条留言
chaosbreaker  [作者] 11 月 24 日 下午 9:46 
Updated for 1.0 release!
decimalist 10 月 13 日 下午 11:58 
This is a great guide for people new to programming! I'd have loved this when I was just learning a few years ago. Wonderful work :steamthis:
chaosbreaker  [作者] 8 月 27 日 上午 11:30 
Thank you CodeAkula for noticing the effort!
CodeAkula 8 月 18 日 上午 4:03 
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  [作者] 5 月 16 日 上午 9:46 
Workbook 1.0 shipped!