Jumping for Lists
Create a program using lists to capture data of physical performance
Questions to investigate
• How can you create a list that represents your personal statistics for performance?
• Ensure SPIKE Prime hubs are charged, especially if connecting through Bluetooth.
(Group Activity, 5 minutes)
Engage students in a conversation about the motion of your body when you do a squat. (For example, your legs bend and your torso gets closer to the ground.) Have students stand up and do a squat.
Next, have students jump in place straight up. Ask students what body movements were made doing the jump.
What are ways to measure how low a body gets during a squat or how high a body is at the apex of a jump?
(Small Groups, 45 minutes)
Students will investigate ways to generate data to include in lists.
Direct students to the BUILD section in the SPIKE App. Here students can access the building instructions for Smart Kettlebell model. Ask students to build the model. The building instructions are also available at https://education.lego.com/en-us/support/spike-prime/building-instructions.
Direct students to open a new project in the Python programming canvas. Ask students to erase any code that is already in the programming area. Students should connect their hub.
Part 1: Create data for your list
Students should program their Kettlebell model to provide several heights for their jumps. Students will use this information to create a list to use later.
Review the sample program with students. Discuss the way that the force and distance sensors are used in this program. Students will use the force sensor to indicate when the jump happens and the distance sensor to measure the height of the jump. Ask students to run the program and see what values they get for their heights.
from spike import PrimeHub, ForceSensor, DistanceSensor from spike.control import wait_until hub = PrimeHub() kettlebell=ForceSensor('B') distance=DistanceSensor('F') while True: kettlebell.wait_until_pressed() print ('JUMP!') kettlebell.wait_until_released() dist_cm=distance.get_distance_cm() print(dist_cm, 'cm')
Note: students should press the force sensor, hold it, jump, and then release the sensor when they are at the height of their jump.
After students explore the program, ask each person on the team to complete three jumps. Students should record the values for each jump in a table.
Part 2: Create your list
Students will create two lists in a new program using the data they generated in part 1.
Discuss with students how to create a new program that will include a list for each student and the data from each of their jumping trials as the values in the list. Remind students the importance of naming variables and lists to easily tell them apart as they program. Here students might use their own names for their individual lists.
Ask students to create their program including both lists, indicating what the maximum value from each list is and then sharing each value on the hub. Introduce the max(name1) line of code to students as a way to indicate their max value in their list.
from spike import PrimeHub, LightMatrix, ForceSensor from spike.control import wait_for_seconds, wait_until hub = PrimeHub() force = ForceSensor('B') \# Create a list for each person using the values from the table. name1=[trial1, trial2, trial3] name2=[trial1, trial2, trial3] \# Print the maximum value from each person's list. print('name1:') print(max(name1)) print('name2:') print(max(name2)) \# Display the max values on the hub when the force sensor is pressed. while True: force.wait_until_pressed() hub.light_matrix.write(max(name1)) hub.light_matrix.show_image('YES') wait_for_seconds(1) hub.light_matrix.write(max(name2)) hub.light_matrix.show_image('YES')
Allow students time to investigate the program trying different ways to show the output or the max value for each list.
Part 3: Putting lists together
Students will modify their program to add their two lists together to make one list.
Explain to students that concatenating lists allows two lists to be combined into one using the + sign. Share with students the example line of code list3 = list1 + list 2 as a way to add lists together. Challenge students to concatenate their lists and find the new max or highest number from both lists.
from spike import PrimeHub, LightMatrix, ForceSensor from spike.control import wait_for_seconds, wait_until hub = PrimeHub() force = ForceSensor('B') \# Create a list for each person using the values from the table. name1=[trial1,trial2, trial3] name2=[trial1,trial2, trial3] \# Print each list. print(name1) print(name2) \# Combine the two lists into one list when force sensor is pressed. Print the list. \# Display the sum of the list on the hub. while True: force.wait_until_pressed() combo_list= name1 + name2 # Print the new list. Then print the sum of the list on the hub. print(combo_list) hub.light_matrix.write(sum(combo_list)) print(sum(combo_list)) hub.light_matrix.show_image('YES')
Allow students time to investigate the program trying different ways to show the output of the sum value for the combined list. Students might also try showing the sum of each list as well as the combined sum.
(Whole Group, 15 minutes)
Discuss with students how the program worked.
Ask students questions like:
• How were you able to generate your own data to include in a list?
• How were you able to incorporate using the force sensor as a button to push for an action to happen?
• How were you able to find different information about your lists (such as sum or max)? What other values do you think you could find?
• How can you combine lists together? When might this be useful?
(Small Groups, 25 minutes)
Challenge students to indicate if a certain number is included in their list.
Discuss with students how to look for information within their lists. While students can easily see the list in their program, there are times when you might need to investigate what has been included in a list. Discuss ways and reasons this could happen as a group.
Ask students to modify their program that has the combo list to identify if the number 20 is included in the combo list. Note: select an appropriate number according to students data.
Share the sample program with students and have them identify how the program is checking the list to see if the number is included.
from spike import PrimeHub, LightMatrix, ForceSensor, DistanceSensor from spike.control import wait_for_seconds, wait_until hub = PrimeHub() force = ForceSensor('B') distance_sensor = DistanceSensor('F') \# create a list for each person using the values from the table. name1=[trial1,trial2, trial3] name2=[trial1,trial2, trial3] \# print each list print(name1) print(name2) \# combine the two lists into one list when force sensor is pressed. Print the list. Display the sum of the list on the hub. while True: force.wait_until_pressed() combo_list= name1 + name2 \# print the new list. Then print the sum of the list on the hub. print(combo_list) hub.light_matrix.write(sum(combo_list)) hub.light_matrix.show_image('YES') wait_for_seconds(2) break \# check to see if data is included in the list if (20 in combo_list): print('the number 20 is in the list') hub.light_matrix.write('YES') else: print('the number 20 is not in the list') hub.light_matrix.write('NO')
Ask students to modify their program similar to the sample program and search for various values to see what is included or not in the program. Students can modify the program in additional ways to indicate if it is or is not included.
(Group Exercise, 10 minutes)
Discuss the program with students.
Ask students questions like:
• What are some ways that you can see using multiple lists?
• What are some ways that lists can benefit you in a program?
• What are different types of information you can take from your lists?
Have students answer the following in their journals:
• What did you learn today about using multiple lists?
• What characteristics of a good teammate did I display today?
• Ask students to rate themselves on a scale of 1-3, on their time management today.
• Ask student to rate themselves on a scale of 1-3, on their materials (parts) management today.
Supporto per l'insegnante
• Create data from the force and distance sensors to use in a list
• Program a list based on the data gathered from the jumping trials (i.e., height of jumps)
• SPIKE Prime sets ready for student use
• Devices with the SPIKE App installed
• Student journals
2-CS-02 Design projects that combine hardware and software components to collect and exchange data.
2-AP-10 Use flowcharts and/or pseudocode to address complex problems as algorithms
2-AP-11 Create clearly named variables that represent different data types and perform operations on their values.
2-AP-13 Decompose problems and subproblems into parts to facilitate the design, implementation, and review of programs.
2-AP-16 Incorporate existing code, media, and libraries into original programs, and give attribution.
2-AP-17 Systematically test and refine programs using a range of test cases.
2-AP-19 Document programs in order to make them easier to follow, test, and debug.