bluecitadel

CODEHS INTRODUCTION TO PROGRAMMING

Dec 14th, 2018
1,097
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.96 KB | None | 0 0
  1. INTRODUCTION TO PROGRAMMING
  2. ===================================
  3. MODULE I: INTRODUCTION TO PROGRAMMING WITH KAREL
  4. ===================================
  5. QUIZ: KAREL COMMANDS
  6. Which of these is a valid Karel command?
  7. - move();
  8. ===================================
  9. 2.1.4: YOUR FIRST KAREL PROGRAM
  10. move();
  11. move();
  12. move();
  13. takeBall();
  14. ===================================
  15. 2.1.5: SHORT STACK
  16. move();
  17. putBall();
  18. putBall();
  19. move();
  20. ===================================
  21. 2.1.6: DANCING KAREL
  22. move();
  23. move();
  24. turnLeft();
  25. turnLeft();
  26. turnLeft();
  27. turnLeft();
  28. ===================================
  29. MODULE II: MORE BASIC KAREL
  30. ===================================
  31. QUIZ: MORE BASIC KAREL
  32. Question: 1
  33. If Karel is facing North and the code
  34.  
  35. turnLeft();
  36. turnLeft();
  37. runs, which direction is Karel facing now?
  38. - South
  39.  
  40. Question: 2
  41. If Karel starts at Street 1 and Avenue 3 facing East, what street (row) and avenue (column) will Karel be on after this code runs?
  42.  
  43. move();
  44. move();
  45. move();
  46. turnLeft();
  47. move();
  48. - Street 2 and Avenue 6
  49.  
  50. Question: 3
  51. What is an avenue in a Karel world?
  52. - A column
  53.  
  54. Question: 4
  55. What is a street in a Karel world?
  56. - A row
  57. ===================================
  58. 2.2.4: MAKE A TOWER
  59. move();
  60. putBall();
  61. turnLeft();
  62. move();
  63. putBall();
  64. move();
  65. putBall();
  66. move();
  67. turnLeft();
  68. turnLeft();
  69. turnLeft();
  70. ===================================
  71. 2.2.5: PYRAMID OF KAREL
  72. putBall();
  73. move();
  74. putBall();
  75. turnLeft();
  76. move();
  77. putBall();
  78. turnLeft();
  79. turnLeft();
  80. move();
  81. turnLeft();
  82. move();
  83. putBall();
  84. turnLeft();
  85. move();
  86. putBall();
  87. move();
  88. putBall();
  89. turnLeft();
  90. turnLeft();
  91. turnLeft();
  92. ===================================
  93. 2.2.6: GO THROUGH THE DOOR
  94. turnleft();
  95. move();
  96. move();
  97. turnLeft();
  98. turnLeft();
  99. turnLeft();
  100. move();
  101. move();
  102. move();
  103. turnLeft();
  104. turnLeft();
  105. turnLeft();
  106. move();
  107. turnLeft();
  108. move();
  109. ===================================
  110. MODULE III: KAREL CAN'T TURN RIGHT
  111. ===================================
  112. QUIZ: KAREL CAN'T TURN RIGHT
  113.  
  114. Question: 1
  115. What can be used to teach Karel to turn right?
  116. - Functions
  117.  
  118. Question: 2
  119. How many times should Karel turn left in order to turn right?
  120. - 3
  121. ===================================
  122. 2.3.4: SLIDE KAREL
  123. function turnRight(){
  124. turnLeft();
  125. turnLeft();
  126. turnLeft();
  127. }
  128.  
  129. putBall();
  130. move();
  131. turnRight();
  132. move();
  133. putBall();
  134. move();
  135. turnLeft();
  136. move();
  137. putBall();
  138. move();
  139. ===================================
  140. 2.3.5: FIREMAN KAREL
  141.  
  142. function turnRight(){
  143. turnLeft();
  144. turnLeft();
  145. turnLeft();
  146. }
  147.  
  148. turnRight();
  149. move();
  150. move();
  151. move();
  152. turnLeft();
  153. ===================================
  154. 2.3.6: REFLECTION: TEACHING KAREL TO TURN RIGHT
  155. ***INDIVIDUAL ASSIGNMENT***
  156. ===================================
  157. MODULE IV: FUNCTIONS IN KAREL
  158. ===================================
  159. QUIZ: FUNCTIONS IN KAREL
  160.  
  161. Which function will teach Karel how to spin in a circle one time?
  162.  
  163. [A]
  164. function spin() {
  165. turnRight();
  166. }
  167. [B]
  168. function spin() {
  169. turnLeft();
  170. turnLeft();
  171. turnLeft();
  172. turnLeft();
  173. }
  174. [C]
  175. function spin() {
  176. turnLeft();
  177. turnLeft();
  178. }
  179. [D]
  180. function spin() {
  181. move();
  182. move();
  183. move();
  184. move();
  185. }
  186. - B
  187. ===================================
  188. 2.4.4: PANCAKES
  189. function start(){
  190. makePancakes();
  191. makePancakes();
  192. makePancakes();
  193. }
  194. function makePancakes(){
  195. move();
  196. putBall();
  197. putBall();
  198. putBall();
  199. move();
  200. }
  201. ===================================
  202. 2.4.5: BACKFLIP
  203. function start(){
  204. backflip();
  205. backflip();
  206. }
  207.  
  208. function backflip(){
  209. move();
  210. turnLeft();
  211. turnLeft();
  212. turnLeft();
  213. turnLeft();
  214. move();
  215. }
  216. ===================================
  217. 2.4.6: DIGGING KAREL
  218. function start(){
  219. buryBall();
  220. buryBall();
  221. buryBall();
  222. }
  223. function buryBall(){
  224. move();
  225. move();
  226. turnRight();
  227. move();
  228. move();
  229. move();
  230. putBall();
  231. turnAround();
  232. move();
  233. move();
  234. move();
  235. turnRight();
  236. move();
  237. }
  238. function turnRight(){
  239. turnLeft();
  240. turnLeft();
  241. turnLeft();
  242. }
  243. function turnAround(){
  244. turnLeft();
  245. turnLeft();
  246. }
  247. ===================================
  248. 2.4.7: BUILD A SHELTER
  249. function start(){
  250. turnLeft();
  251. makeSide();
  252. turnRight();
  253. makeSide();
  254. turnRight();
  255. makeSide();
  256. goHome();
  257. }
  258. function turnRight(){
  259. turnLeft();
  260. turnLeft();
  261. turnLeft();
  262. }
  263. function makeSide(){
  264. move();
  265. putBall();
  266. move();
  267. putBall();
  268. move();
  269. putBall();
  270. }
  271. function goHome(){
  272. turnRight();
  273. move();
  274. move();
  275. move();
  276. turnLeft();
  277. turnLeft();
  278. }
  279. ===================================
  280. MODULE V: THE START FUNCTION
  281. ===================================
  282. QUIZ: THE START FUNCTION
  283.  
  284. How many times should you call the start function when writing your program?
  285. - 0
  286. How many times should the start function be defined in a program?
  287. - 1
  288. ===================================
  289. 2.5.4: PANCAKES WITH START
  290. function start(){
  291. makePancakes();
  292. makePancakes();
  293. makePancakes();
  294. }
  295. function makePancakes(){
  296. move();
  297. putBall();
  298. putBall();
  299. putBall();
  300. move();
  301. }
  302. ===================================
  303. 2.5.5: DIGGING KAREL WITH START
  304. function start(){
  305. buryBall();
  306. buryBall();
  307. buryBall();
  308. }
  309. function turnRight(){
  310. turnLeft();
  311. turnLeft();
  312. turnLeft();
  313. }
  314. function buryBall(){
  315. move();
  316. move();
  317. turnRight();
  318. move();
  319. move();
  320. move();
  321. putBall();
  322. turnLeft();
  323. turnLeft();
  324. move();
  325. move();
  326. move();
  327. turnRight();
  328. move();
  329. }
  330. ===================================
  331. MODULE VI: TOP DOWN DESIGN AND DECOMPOSITION WITH KAREL
  332. ===================================
  333. QUIZ: TOP DOWN DESIGN AND DECOMPOSITION
  334. Question: 1
  335. Why do we use functions in programming?
  336. - All of the above
  337. Question: 2
  338. What is top down design?
  339. - Top down design is a way of designing your program by starting with the biggest problem and breaking it down into smaller and smaller pieces that are easier to solve.
  340. ===================================
  341. 2.6.4: THE TWO TOWERS
  342. function start(){
  343. makeTower();
  344. move();
  345. move();
  346. turnLeft();
  347. move();
  348. makeTower();
  349. move();
  350. turnRight();
  351. }
  352. function turnRight(){
  353. turnLeft();
  354. turnLeft();
  355. turnLeft();
  356. }
  357. function makeTower(){
  358. move();
  359. putBall();
  360. turnLeft();
  361. move();
  362. putBall();
  363. move();
  364. putBall();
  365. }
  366. ===================================
  367. 2.6.5: MAKE A 'Z'
  368. function start(){
  369. putBallsInRow();
  370. makeDiagonal();
  371. move();
  372. turnLeft();
  373. turnLeft();
  374. putBallsInRow();
  375. }
  376. function turnRight(){
  377. turnLeft();
  378. turnLeft();
  379. turnLeft();
  380. }
  381. // PLACES FOUR BALLS IN A ROW
  382. function putBallsInRow(){
  383. move();
  384. putBall();
  385. move();
  386. putBall();
  387. move();
  388. putBall();
  389. move();
  390. putBall();
  391. }
  392. // MAKES A DIAGONAL LINE OF BALLS
  393. function makeDiagonal(){
  394. turnRight();
  395. move();
  396. turnRight();
  397. move();
  398. putBall();
  399. turnLeft();
  400. move();
  401. turnRight();
  402. move();
  403. putBall();
  404. turnLeft();
  405. move();
  406. turnRight();
  407. move();
  408. }
  409. ===================================
  410. REFLECTION: TOP-DOWN DESIGN
  411. *** INDIVIDUAL ASSIGNMENT ***
  412. ===================================
  413. MODULE VII: COMMENTING YOUR CODE
  414. ===================================
  415. QUIZ: COMMENTING YOUR CODE
  416. Question: 1
  417. What is a code comment?
  418. - A way to give notes to the reader to explain what your code is doing
  419. ===================================
  420. 2.7.4: THE TWO TOWERS + COMMENTS
  421. // FUNCTION START() MAKES THE PROGRAM RUN AND MAKE TOWERS ONE AND TWO
  422. function start(){
  423. makeTower();
  424. move();
  425. move();
  426. turnLeft();
  427. move();
  428. makeTower();
  429. move();
  430. turnRight();
  431. }
  432. // MAKES KAREL TURN RIGHT USING THREE LEFT TURNS
  433. function turnRight(){
  434. turnLeft();
  435. turnLeft();
  436. turnLeft();
  437. }
  438. // KAREL DRAWS A TOWER
  439. function makeTower(){
  440. move();
  441. putBall();
  442. turnLeft();
  443. move();
  444. putBall();
  445. move();
  446. putBall();
  447. }
  448. ===================================
  449. REFLECTION: COMMENTING
  450. *** INDIVIDUAL ASSIGNMENT ***
  451. ===================================
  452. MODULE VII: ABSTRACTION
  453. ===================================
  454. QUIZ: ABSTRACTION
  455. Question: 1
  456. Karel needs to pick up a pile of tennis balls.
  457. Which of the following start functions solves the problem at the highest level of abstraction?
  458. - function start() {
  459. moveToPile();
  460. takePile();
  461.  
  462. }
  463. Question: 2
  464. Each of the following answer choices describes a basketball game.
  465. Which answer choice describes the game with the lowest level of abstraction?
  466. - First, Steph Curry flexed his left and right quad muscles at the exact same time, then he flexed each muscle in his fingers…
  467. ===================================
  468. 2.8.4: ABSTRACTING YOUR DAY
  469. *** INDIVIDUAL ASSIGNMENT ***
  470. ===================================
  471. 2.8.5: REFLECTION: ABSTRACTION
  472. *** INDIVIDUAL ASSIGNMENT ***
  473. ===================================
  474. 2.8.6: ABSTRACTION IN KAREL
  475. *** INDIVIDUAL ASSIGNMENT ***
  476. ===================================
  477. MODULE IX: SUPER KAREL
  478. ===================================
  479. QUIZ: SUPER KAREL
  480. Question: 1
  481. What commands does SuperKarel know that regular Karel does not?
  482. - turnAround() and turnRight()
  483. ===================================
  484. 2.9.4: THE TWO TOWERS + SUPER KAREL
  485. // THE START FUNCTION MAKES THE PROGRAM RUN
  486. function start(){
  487. makeTower();
  488. move();
  489. move();
  490. turnLeft();
  491. move();
  492. makeTower();
  493. turnAround();
  494. move();
  495. turnRight();
  496. }
  497. // KAREL PLACES BALLS IN A TOWER
  498. function makeTower(){
  499. move();
  500. putBall();
  501. turnLeft();
  502. move();
  503. putBall();
  504. move();
  505. putBall();
  506. turnAround();
  507. }
  508. ===================================
  509. MODULE X: FOR LOOPS
  510. ===================================
  511. QUIZ: FOR LOOPS
  512. Question: 1
  513. What is the best way for Karel to move 10 times?
  514. - for (var i = 0; i < 10; i++) {
  515. move();
  516. }
  517. ===================================
  518. 2.10.5: TAKE 'EM ALL
  519. function start(){
  520. move();
  521. for(var i = 0; i < 100; i++){
  522. takeBall();
  523. }
  524. move();
  525. }
  526. ===================================
  527. 2.10.6: DIZZY KAREL
  528. // KAREL SPINS FOR ALL INSTANCES EQUAL TO AND LESS THAN 32
  529. function start(){
  530. for(var i = 0; i < 32; i++){
  531. turnLeft();
  532. }
  533. }
  534. ===================================
  535. 2.10.7: FOR LOOP SQUARE
  536. /* TRY TO LAY DOWN A SQUARE OF FOUR TENNIS BALLS
  537. * USING A FOR LOOP
  538. */
  539. function start(){
  540. for(var i = 0; i < 4; i++){
  541. putBall();
  542. move();
  543. turnLeft();
  544. }
  545. }
  546. ===================================
Add Comment
Please, Sign In to add comment