Review: Variables

Module 1: Python Fundamentals

Review of Session 1.1: Variables

Exercise

Without running the code, what is going to be the output of this cell?

x = 4
print(x)

y = 2 *2
print(y)
Exercise

Without running the code, what is going to be the output of this cell?

msg = "Pi is"  "3.14"
print(msg)
Exercise

How would you print a message with a quote? For instance, print: The cow says “Moooo”

# We can use single quotation marks
print("The cow says 'Moooo'")

# It also works the other way around!
print('The cow says "Moooo"')
Exercise

Which ones print statement will fail? (May be more than one)

# A)
print("The number 3.14 is close to pi")

# B)
print(f"The number {3.1415.2f} is close to pi")

# C)
number = 3.1415
print(f"The number {number:.2f} is close to pi")

# D)
number = 3.1415
print(f"The number", number, " is close to pi")

# E)
number = 3.1415
print("The number" + number + "is close to pi")

# F)
number = "3.14"
print("The number", number, "is close to pi")
Exercise

What will be the output of the following code blocks?

pet = "dog"

msg = f"I have a {pet}"

print(msg)
pet = "dog"

msg = f"I have a {pet}"

pet = "cat"

print(msg)
x = 1

y = 3 * x

x = 2

y = 2 * x

print(y)