1 / 6

Week 11 DO NOW QUESTIONS

Week 11 DO NOW QUESTIONS.

habib
Download Presentation

Week 11 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 11 DO NOW QUESTIONS

  2. An ask turtles block is a set of instructions that is issued to every turtle. Even though computers can do things very quickly, some problems are still too big to handle. It is important to be able to have a rough idea of how many operations your code is going to execute when a block runs. Look at the two ask turtle blocks below and determine which one does more “work”. Both block call the procedure “wiggle”. Both procedures are only called once (no forever buttons). to wiggle right random 15 left random 16 forward 1 end A. to test-A Create-turtles 100 Ask turtles [ setxy random 16 random 16 Pen-down wiggle set pcolor green pen-up ] end B. to test-B Create-turtles 50 [ ask turtles [ setxy random 16 random 16 set shape “ant” set color red ask n-of 10 other turtles [wiggle] ] end • Block A runs more operations because there are more turtles. • Block A does more “work” because it moves the pen up and down. • Block B executes many more wiggle operations than Block A. It would probably take longer to run. • Block B does more work because it sets a shape. Graphics use lots of memory.

  3. You are trying to understand a NetLogo program written by another programmer. You come across the following line of code Set x = 3 What does it do? • Sets x equal to the value 3 • It causes an error. The programmer probably meant: set x 3. • Creates a variable x and tests if it is equal to three • Creates an agentset with 3 members. • Both a and c

  4. You have code that creates a list, L and then runs several commands at once on that list. Make sure that you start with the innermost command and work your way out. The code shows the results in the command center window with the “show” command. • Thebutfirst command removes the “j” from [ "j" "e" "M" " " "p" "l" "e" "d"] • Thebutlast command removes the “d” from [ "e" "M" " " "p" "l" "e" "d"] • Reverse requires one list as input, in this case it gets [ "e" "l" "p" "M" "e" ] • fputadds an “H” to the front the result of reverse butlastbutfirstMyListand you get ["H" "e" "l" "p" " " "M" "e"] • All of the above are true.

  5. The show or type commands are very useful debugging tools. They allow the programmer to peek at the values the of variables or attributes. If we use a couple of type commands as below what will be the output? • Ha Ha 0 Ha Ha 0 Ha Ha 0 • Fifty 0’s and 50 Ha Ha’s • Ha Ha xcor • Nothing will be printed because the turtles all die.

  6. Here is a simple reporter that adds two numbers. It has two input parameters so you need to pass it two arguments when you call it. It returns a single number. Remember, when you write a reporter, you put the parameter(s) in square brackets. When you call or use it, you just pass an argument of the right type (string, number value, or list.) Now, lets call this reporter like the one below. What does this code do? • It won’t work because adds-two-numbers needs two arguments. • It gives an error because you forgot the square brackets. • The 1 and the 4 get added and the 2 and the 5 get added. • The first adds-two-numbers gets its input only after the other adds-two-numbers reporters run. This code sums the four numbers.

More Related