1 / 6

Week 7 DO NOW QUESTIONS

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 ]

raina
Download Presentation

Week 7 DO NOW QUESTIONS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Week 7DO NOW QUESTIONS

  2. 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

  3. 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

  4. 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.

  5. 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”

  6. 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.

More Related