Data Abstraction Homework Python
Quick practice with Javascript Lists
# 📝 Data Abstraction Hack (Python Version)
# --- Instructions ---
# 1. Edit the `students` list to use your own names (friends, classmates, etc.).
# 2. Edit the `scores` list to assign each student a score of your choice.
# 3. Run this program to see how the output changes automatically.
# 4. After experimenting with `students` and `scores`, complete the 🚀 Hack Challenge at the bottom.
# --- 1. Define lists ---
students = ["Vivian", "Sarah", "Paul"]
scores = [89, 20000, 78]
# --- 2. Print roster ---
print("Students:", ", ".join(students))
# --- 3. Print first student and score ---
print("First student:", students[0], "-", scores[0])
# --- 4. Add a new student and score ---
students.append("Dana")
scores.append(95)
print("After adding Dana:", ", ".join(students))
# --- 5. Remove a student who transfers out ---
if "Paul" in students:
index = students.index("Paul")
students.pop(index)
scores.pop(index)
print("After removing Paul:", ", ".join(students))
# --- 6. Curve all scores by +5 ---
for i in range(len(scores)):
scores[i] += 5
# --- 7. Print each student with score ---
print("\nFinal Scores:")
for i in range(len(students)):
print(students[i], "-", scores[i])
# --- 8. Hack Challenge: create new list ---
favorite_foods = ["Sushi", "Falafel", "Hotdogs"]
print("\nFavorite Foods:")
for food in favorite_foods:
print(food)
Students: Vivian, Sarah, Paul
First student: Vivian - 89
After adding Dana: Vivian, Sarah, Paul, Dana
After removing Paul: Vivian, Sarah, Dana
Final Scores:
Vivian - 94
Sarah - 20005
Dana - 100
Favorite Foods:
Sushi
Falafel
Hotdogs