Group One Lesson Hacks 4/21
Code and ideas for main page Tri 3 Project
Answered Questions and Hacks
-
2D Array:
-
What are some examples of 2d Arrays Some Examples of 2D arrays are:
- [["Ice Cream","Calories","Rating"],["Mint Chip","270","10"],["Java Chip","350","8"],["Coffee","170","9"]]
- [["Dance","Calories Burned","Popularity"],["Hip Hop","150","6"],["Ballet","100","9"]]
-
What is a modern day game that could be classified as a 2D array Chess and checkers are modern day games that are classified and can be implemented as 2D arrays.
-
Describe a 2D array in your own words: A 2D array is when items are organized in a grid-like structure and is implemented by writing lists of similar values in one list.
-
-
Iteration
-
What is the definition of iteration in your own words Iteration is the process of looping code (to simplify) until an end goal is achieved.
-
Explain how the game relates to iteration: The game uses loops to repeat the given steps (up,down,left,right) until it reaches the goal (hitting the dot). The code loops through the directions to move the robot.
-
What parts of the code use iteration In the code written below this question, iteration is used in the for loops. For every direction given, the code runs through the program until a given condition, or instruction for movement, is completed.
-
-
List and Dictionaries
-
Explain which parts of the code use lists In this card example, there are dictionaries within the list, CardArray. Word list is also a list of words that are used in the unscrambling game in which the program selects one word from to be the scrambled word.
-
Explain what list manipulation is happening in that part In this code segment, the list is being indexed to find the word that has been chosen to be unscrambled. This word is also indexed to give hints about the letters within
-
Iteration 0.2 (can get up to 0.23)
-
Get to level 5
- Take ScreenShots of your name inside the box an put them in your ticket
-
Level One:
-
Level Two:
-
Level Three:
-
Level Four:
-
Level Five:
- Create a code segment with iteration that does something cool Below:
flavors = ['vanilla', 'chocolate', 'strawberry', 'mint chocolate chip']
# Iterate through list to print
for flavor in flavors:
print(flavor)
# This prints the first letter only
for flavor in flavors:
print(flavor[0])
2D array 0.2 (can get up to 0.23)
-
Explain how the tic tac toe game works The tic tac tow game works by creating a 2D array of am empty board. The board is randomly generated by manipulating the empty board and adding values. The game then iterates through the game program and checks for ties and wins. The program will continue to iterate through until the game is over.
-
Give 3 Examples of games that can be made from 2D arrays Three examples of games that can be made from 2D arrays are chess, checkers, and connect 4.
List and Dictionaries 0.2 (can get up to 0.23)
-
Explain the differences between Lists and Dictionaries Lists or arrays only contain items, while dictionaries contain keys and values. Although, lists can contain dictionaries and dictionaries can contain lists. Lists are written using [], and dictionaries use {}. Lists are more flexible with the types of data they contain as well. Both are able to be indexed, either by index numbers or key values.
-
Make a code block that manipulates either a list or a dictionary. below:
flavors = {'vanilla': 2.0, 'chocolate': 2.5, 'strawberry': 3.0, 'mint chocolate chip': 3.5}
# Add a new flavor and its price to the dictionary
flavors['caramel'] = 4.0
print(flavors)
del flavors['vanilla']
print(flavors)
flavors['chocolate'] = 3.0
print(flavors)