60 likes | 169 Views
Week 7 DO NOW QUESTIONS. Question: In the following segment of code, “food-location” is a ___? breed [ foragers forager ] breed [ followers follower ] foragers -own [ food-location food-distance food-found? ] followers -own [ foragers-food-location forager-distance ]
E N D
Question: In the following segment of code, “food-location” is a ___? breed [ foragers forager ] breed [ followers follower ] foragers-own [ food-location food-distance food-found? ] followers-own [ foragers-food-location forager-distance ] • Local variable • Global variable • Turtle variable • None of the above, they are patch variables
Question: What is the result of running the following setup procedure ? to setup create-turtles 10 [ set color red ] ask turtles [ hatch 1 ] end • There will be 10 red turtles • There will be 20 red turtles • There will be 11 turtles • There will be 10 red turtles and 1 non-red turtle
Question: In the following piece of code, the programmer wants each of the 10 turtles created to hatch an offspring. Does this go-forever procedure do what she wants? to setup create-turtles 10 end to go-forever ask turtles [ hatch 1 [ set color red ] ] end • No, the turtles will reproduce forever. • No, only 1 new turtle will be created. • Maybe, it depends on how many turtles were created to begin with. • Yes, 20 turtles will be created.
Question: In the following piece of code, the programmer wants turtles to reproduce if they have more energy of greater than 10. Will this piece of code do what he intends? Turtles-own [energy] to go-one-time set energy 0 Ask turtles [ forward 10 set energy energy - .05 if energy < 0 [ die ] if energy > 10 [hatch 1] ] end • Yes, turtles will give birth if they have enough energy • No, the turtles will all die before giving birth • No, it should say if “energy > 9” • No, it should say if “energy = 10”
Question:In the following piece of code, the programmer wants turtles to reproduce if they have more energy of greater than 100. Will this piece of code do what he intends? Turtles-own [energy] to setup clear-all create-turtles 10 [set energy 100] end to go-one-time Ask turtles [ forward 1 set energy energy - .05 if pcolor = green [ set energy energy + .1 ] if energy > 100 [ hatch 1 ] ] end • A turtle’s energy cannot be set outside of Ask-turtles [ ] • A turtle’s energy is never being updated • There is no error • A turtle’s energy should start at 0 not 100.