2nd Semester Intro to Computer Science

What you will learn

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

  1. Read through the code and write down what you expect the printed results to be?
  2. Run the code and write down the actual printed result?
  3. Briefly describe what the # does?
  4. Briefly describe what input does?

Snap to Python

Convert the following to Python code:

Snap Input

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)
  1. Run the program. What is the output?
  2. Write code to swap the values of variables a and b.

Lab

Project Objective

Project Specifications

magic_genie_output

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.

magic_genie_output_confused

SNAP Flashback – Magic Genie

Genie Code - Snap

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 name to the text “Your name? “
  • Shows the prompt, waits for the user to type, and stores what they typed in name
  • Compares name to 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?

  • x is “red” and y is “blue”
  • x is “red” and y is “red”
  • x is “blue” and y is “red”
  • x is “blue” and y is “blue”

Assignment copies the right-hand value into the left-hand variable, so the old value of x is lost and both hold "blue".

Downloads