Variables & Assignment Homework


Description:

  • In this homework hack, you will practice creating and using variables. You’ll define variables to store your name and age, reassign values, and answer interactive questions to test your understanding. This activity will help you master the basics of variables and how they work in programming.

🏠 Variables Quest Homework

Objective: Practice creating, manipulating, and combining strings in Python.


Instructions

Complete each challenge by filling in the missing code. Use the examples as a guide, but make sure to write your own values or logic.

Challenge 1: Creating a Life Profile with Variables

# Part 1
## Personal info
my_name = "Meryl"       # Fill in your name
my_age = 15             # Fill in your age
my_city = "San Diego"   # Fill in the city where you live

# Part 2
## Preferences
favorite_color = "Blue"     # Your favorite color
favorite_food = "Ramen"     # Your favorite food
favorite_movie = "Movie"    # Your favorite movie
favorite_song = "JJ"        # Your favorite song

# Part 3
# Reassign some variables
favorite_food = "RJM"
my_city = "HZ"
has_pet = "no"

# Part 4 (missing variables, I added defaults)
is_student = True
is_online = True
likes_music = True

# Part 5: Print Your Life Profile
# Print all your variables so your "Life Profile" is displayed:

print("Name:", my_name)
print("Age:", my_age)
print("City:", my_city)
print("Favorite color:", favorite_color)
print("Favorite food:", favorite_food)
print("Favorite movie:", favorite_movie)
print("Favorite song:", favorite_song)
print("Student?", is_student)
print("Has pet?", has_pet)
print("Online?", is_online)
print("Likes music?", likes_music)

Name: Meryl
Age: 15
City: HZ
Favorite color: Blue
Favorite food: RJM
Favorite movie: Movie
Favorite song: JJ
Student? True
Has pet? no
Online? True
Likes music? True

Task 2

Creative Challenge

Your task: Create a “story” or “profile” using ONLY variables and assignments.

Instructions:

  1. Create at least 8 variables to describe a character or yourself.
    Examples:
    name, age, favorite_food, hobby, number_of_pets, mood, favorite_color, dream_job

  2. Assign initial values to all variables.

  3. Reassign at least 4 of the variables to new values to simulate changes over time or “events” in the story.

  4. Use print statements to write a story or profile that is at least 5 sentences long.
    Each sentence should include at least one variable.
    Example:

    “Tanay (‘age’ 17) loves pizza and plays tennis (‘hobby’) every weekend. Today, Tanay is happy because he ate his (‘favoirite_food’).”

  5. Optional: Add extra variables to make your story longer and more creative.
    You can also create “day 2”, “day 3”, etc., by reassigning variables and printing new sentences.

Goal:

  • Show creativity while practicing:
    • Variable creation
    • Variable reassignment
    • Using variables in print statements
    • Experiment with assigment and reassigment to update variables
# Step 1: Create variables
name = "Kailyn"
age = 16
favorite_food = "sushi"
hobby = "painting"
number_of_pets = 2
mood = "excited"
favorite_color = "blue"
dream_job = "marine biologist"

# Step 2: Initial story
print(name, "is", age, "years old and loves", favorite_food + ".")
print(name, "spends most weekends", hobby + ".")
print("She has", number_of_pets, "pets and feels", mood, "every morning.")
print("Her favorite color is", favorite_color, "because it reminds her of the ocean.")
print("In the future,", name, "wants to be a", dream_job + ".")

# Step 3: Reassign variables
age = 16
favorite_food = "ramen"
hobby = "surfing"
mood = "tired"
number_of_pets = 3

# Step 4: Updated story
print("\nA year later...")
print(name, "is now", age, "years old.")
print("Her favorite food changed to", favorite_food, "and she started", hobby + ".")
print("She has", number_of_pets, "pets now and feels", mood, "after surfing early in the morning.")
print("Even though things changed,", name, "still dreams of becoming a", dream_job + ".")

Kailyn is 16 years old and loves sushi.
Kailyn spends most weekends painting.
She has 2 pets and feels excited every morning.
Her favorite color is blue because it reminds her of the ocean.
In the future, Kailyn wants to be a marine biologist.

A year later...
Kailyn is now 16 years old.
Her favorite food changed to ramen and she started surfing.
She has 3 pets now and feels tired after surfing early in the morning.
Even though things changed, Kailyn still dreams of becoming a marine biologist.