Fall 2024 - P4
Big Idea 3 | .1 | .2 | .3 | .4 | .5 | .6 | .7 | .8 | .10 |
3.2 Data Abstraction
Student led teaching on Abstraction. Teaching how various data types can use abstraction for computational efficiency.
Python Popcorn Hacks
P.S: Do homework/popcorn hacks at the bottom:
Popcorn Hack #1
Step 1: Create a Set
Create a set: {1, 2, 3, 4, 5}
.
Step 2: Add an Element
Add 6
to the set.
Step 3: Remove an Element
Remove 2
from the set.
Step 4: Union of Sets
Union with {7, 8, 9}
.
Step 5: Clear the Set
Clear the set.
Bonus:
- Create a set with duplicates:
{1, 2, 2, 3, 3, 4}
. - Find the length with
len()
.
Popcorn Hack #2
Step 1: Create a String
Create a string: "Learning Python is not fun"
.
Step 2: String Length
Find the length of the string using len()
.
Step 3: String Slicing
Extract "Python"
from the string using slicing.
Step 4: String Uppercase
Convert the string to all uppercase letters.
Step 5: String Replace
Replace "fun"
with "good"
.
Bonus:
Reverse the string using slicing.
Popcorn Hack #3
Step 1: Create a List
Create a list of numbers: [3, 5, 7, 9, 11]
.
Step 2: Access an Element
Access the third element of the list.
Step 3: Modify an Element
Change the second element to 6
.
Step 4: Add an Element
Append 13
to the list.
Step 5: Remove an Element
Remove the element 9
from the list.
Bonus:
Sort the list in descending order.
Popcorn Hack #4
Step 1: Create a Dictionary
Create a dictionary called personal_info, and have it include “name”, “email”, “phone number”. They can be anything.
Step 2: Print out the Dictionary:
Print out the entire Dictionary you made.
Step 3: Print out the name from your dictionary:
Print out the name that you put in your dictionary. First print out “My Name is:”, then print out the name.
Step 4: Print the Length:
Print the Overall Length of the Dictionary using len()
Step 5: Print the Type:
Print the Overall Type of the Dictionary using type()
Bonus:
Add another dictionary with the same thing “name” “email” “phone number” and print their different values.
Homework Hacks (Python)
Part 1: Create Personal Info (dict)
Create a dictionary called personal_info
that includes the following keys. Assign values to the keys: full_name
, years
, location
, and favorite_food
. The full_name
should be a string, years
an integer, location
a string, and favorite_food
a string.
See Answer
```python personal_info = { "full_name": "John Doe", "years": 25, "location": "New York", "favorite_food": "Pizza" } ```Part 2: Create a List of Activities (list)
Create a list called activities
that includes three of your favorite activities as strings. Print the activities
list.
See Answer
```python activities = ["Running", "Reading", "Gaming"] print(activities) ```Part 3: Add Activities to Personal Info (dict and list)
Add the activities
list to the personal_info
dictionary under the key activities
. Print the updated personal_info
dictionary.
See Answer
```python personal_info["activities"] = activities print(personal_info) ```Part 4: Check Availability of an Activity (bool)
Choose one of your activities and create a boolean variable called activity_available
. Set activity_available
to True
if your activity is available today, otherwise set it to False
. Print a message using activity_available
like: “Is «your activity» available today? «True/False»”
See Answer
```python activity_available = True # or False print(f"Is Running available today? {activity_available}") ```Part 5: Total Number of Activities (int)
Create a variable called total_activities
and set it to the number of activities in your activities
list. Print a message like: “I have «total_activities» activities.”
See Answer
```python total_activities = len(activities) print(f"I have {total_activities} activities.") ```Part 6: Favorite Activities (tuple)
Create a tuple called favorite_activities
that contains your two most favorite activities. Print the favorite_activities
tuple.
See Answer
```python favorite_activities = ("Running", "Reading") print(favorite_activities) ```Part 7: Add a New Set of Skills (set)
Create a set called skills
and add three unique skills you have. Print the set of skills
.
See Answer
```python skills = {"Coding", "Cooking", "Photography"} print(skills) ```Part 8: Consider a New Skill (NoneType)
You are thinking about learning a new skill. Create a variable called new_skill
and set it to None
(you haven’t decided yet). Print the value of new_skill
.
See Answer
```python new_skill = None print(new_skill) ```Part 9: Calculate Total Hobby and Skill Cost (float)
Assume each activity costs $5 to pursue and each skill costs $10 to develop. Create a variable called total_cost
as a float, and calculate how much it would cost to develop all your activities and skills. Print the total cost.
See Answer
```python total_cost = (len(activities) * 5) + (len(skills) * 10) print(f"Total cost: ${total_cost}") ```Javascript Popcorn Hacks
Popcorn Hack 1 (SETS):
-Create a set called [Set1] of 3 numbers (can be any number)
-Create a set called [Set2] of different 3 numbers (can be any number) -log both sets separately
-Add a number and Remove the 1st number from set1
-log the union of both Set1 and Set2.
Popcorn Hack 2 (Dictionaries):
-Create a Dictionary called “application” that has someones “name”, “age”, “experiences”, and “money”.
-log the dictionary to make sure it works
-log only the dictionarie’s money
Homework Hack:
-Make an application for an applicant, ask them questions about their name, age, and experiences.
-Store these inputs into a Dictionary, sorting each of their responses into “name”, “age”, and “experiences”
-Log the users input
Grading Rubric (Homework)
Criteria | Outstanding (90-100) | Good (80-89) | Fair (70-79) | Needs Improvement (Below 70) | Weight |
---|---|---|---|---|---|
Code Elements | Utilizes all 9 data types effectively. | Includes 7 different data types. | Incorporates 5 data types. | Includes 4 or fewer data types. | 20% |
Organization | Well-structured and easy to follow. | Mostly organized; some minor tweaks. | Somewhat disorganized; harder to follow. | Lacks clarity, difficult to follow. | 20% |
Functionality | Seamlessly integrates into the project. | Functions well, but lacks cohesion. | Functional but disjointed. | Poorly integrated, doesn’t fit the project. | 50% |
Creativity | Highly original and innovative ideas. | Some unique ideas but mostly typical. | Limited originality, common ideas. | Lacks creativity, very predictable. | 10% |
Total Score Calculation:
- Outstanding: 90-100
- Good: 80-89
- Fair: 70-79
- Needs Improvement: Below 70
# POPCORN PYTHON 1
# POPCORN PYTHON 2
# POPCORN PYTHON 3
# POPCORN PYTHON 4
# HOMEWORK PYTHON
// POPCORN JAVASCRIPT 1
// POPCORN JAVASCRIPT 2
// HOMEWORK JAVASCRIPT