What you will learn
- Define and identify: comments, storing, mutability, variable assignment, input
- Assign and swap variables
- Store user input into a variable
Reading
Do Now
1. In your Console
Type and run the following code
a = input("What is your name? ")
# a = "cats and dogs"
# meow
print("Hello there, " + a)
In your Notebook
Answer the following questions
- Read through the code and write down what you expect the printed results to be?
- Run the code and write down the actual printed result?
- Briefly describe what the
#does? - Briefly describe what
inputdoes?
Snap to Python
Convert the following to Python code:

Swapping
2. In your Console
Type and run the following
a = "this sentence should go second"
b = "this sentence should go first."
# your code starts here
# your code ends here
print(a)
print(b)
- Run the program. What is the output?
- Write code to swap the values of variables
aandb.
Lab
Project Objective
- Use Python to interact with variables and user input
- Create a genie program. Save the file as
magic_genie.py.
Project Specifications
- Have the program introduce itself
- Have the program ask for three separate wishes
- Print all the wishes togethe

- There are some repeated strings in this genie program. Move those into variables
Genie Confusion
Now it’s time to make your genie confused. Edit your code to have him print your first wish as your last wish, and your second wish as your first wish, and your third wish as your second wish.

SNAP Flashback – Magic Genie

Hint
Remember to add spaces you can combine " " to the end of your string using the + operator. So print("hello" + " " + "student") would print hello student
Check your understanding
Pick an answer for each question. You can try again until you get it right.
1. What does name = input("Your name? ") do?
- Prints “Your name?” and then forgets it
- Sets
nameto the text “Your name? “ - Shows the prompt, waits for the user to type, and stores what they typed in
name - Compares
nameto the user’s typing
The input function displays the prompt, waits for the user, and returns what they typed so it can be stored in a variable.
2. What does the # do in a line like # add the tax?
- Starts a comment that Python ignores
- Makes Python print the line
- Causes an error
- Stores the line in a variable
Everything after a # is a comment meant for humans, and Python skips it.
3. After x = "red", y = "blue", and x = y, what are x and y?
xis “red” andyis “blue”xis “red” andyis “red”xis “blue” andyis “red”xis “blue” andyis “blue”
Assignment copies the right-hand value into the left-hand variable, so the old value of x is lost and both hold "blue".