Variables & Assignment Homework - CTRL Zombies


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 = "Hope"           # Fill in your name
my_age = 16            # Fill in your age
my_city = "San Diego"           # Fill in the city where you live

# Part 2
## Preferences
favorite_color = "Purple"    # Your favorite color
favorite_food = "Chicken"     # Your favorite food
favorite_movie = "My Little Pony"    # Your favorite movie
favorite_song = "Taste"     # Your favorite song

# Part 3
# Reassign some variables
favorite_food = "Pizza"
my_city = "Los Angeles"
has_pet = True
is_online = False
is_student = 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: Hope
Age: 16
City: Los Angeles
Favorite color: Purple
Favorite food: Pizza
Favorite movie: My Little Pony
Favorite song: Taste
Student? True
Has pet? True
Online? False
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
print("Day 1")

name = "Hope"
age = 16
favorite_food = "chicken"
hobby = "listening to music"
number_of_pets = 1
mood = "tired"
favorite_color = "purple"
dream_job = "gamer"

print(f"{name}, age {age}, loves eating {favorite_food} after spending some time {hobby}.")
print(f"She currently has {number_of_pets} pet and feels very {mood}")
print(f"{name}'s favorite color is {favorite_color}, and she wants to be a {dream_job}.")

favorite_food = "pasta"
hobby = "sleeping"
number_of_pets = 2
mood = "bored"

print("Day 2")
print(f"{name}'s interests changed.")
print(f"Now she likes eating {favorite_food} after {hobby}.")
print(f"She has another pet, so now she has {number_of_pets}!")
print(f"{name} feels {mood}.")

Day 1
Hope, age 16, loves eating chicken after spending some time listening to music.
She currently has 1 pet and feels very tired
Hope's favorite color is purple, and she wants to be a gamer.
Day 2
Hope's interests changed.
Now she likes eating pasta after sleeping.
She has another pet, so now she has 2!
Hope feels bored.
# # Finish the code 
# Define the win/lose messages first
messageWin = "You Win!" # <-- Change this to "You win!"
messageLose = "You Lose!" # <-- Change this to "You lose!"

# Choose outcome
winOrLose = "win"  # <-- Change this to either "win" or "lose"

# Print result
if winOrLose == "win":
    print(messageWin)
else:
    print(messageLose)

You Win!
# Finish the code 
# Example: snakeSize = 10
snakeSize = 20   # <-- Add the size of the snake
snakeColor = "green"   # <-- Add the color of the snake

# Print greeting
print("The snake is " + str(snakeSize) + " inches long and it's " + snakeColor + ".")

The snake is 20 inches long and it's green.