Advertisement
hyungu

Table Data Exercise

Mar 31st, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. Write code to print the row for the name "Atticus".
  2.  
  3. table = new SimpleTable("baby-2010.csv");
  4. for (row: table) {
  5. if(row.getField("name") == "Atticus"){
  6.  
  7. print(row);
  8.  
  9. }
  10.  
  11. }
  12.  
  13. ----------------------------------------------------
  14. Write code to print the rows for the name "River". In this case, there are two such rows, but the same basic code pattern as for question 1 works. This shows how the loop really is just testing every row.
  15.  
  16. table = new SimpleTable("baby-2010.csv");
  17. for (row: table) {
  18. if(row.getField("name") == "River") {
  19. print(row);
  20. }
  21.  
  22. }
  23.  
  24. ----------------------------------------------------
  25. Write code to print the rows where the rank is less than (<) 10, i.e. ranks 1 through 9.
  26.  
  27. table = new SimpleTable("baby-2010.csv");
  28. for (row: table) {
  29. if(row.getField("rank") < 10) {
  30. print(row);
  31. }
  32.  
  33. }
  34.  
  35. ----------------------------------------------------
  36.  
  37. Write code to print the rows where the rank is greater than 950.
  38.  
  39. table = new SimpleTable("baby-2010.csv");
  40. for (row: table) {
  41. if(row.getField("rank") > 950) {
  42. print(row);
  43.  
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement