Drill - Values and Variables

Introduction

Drills are very short exercises designed to exercise the most basic building blocks of modules and programs. In this drill you will create a series of values and assign them to variables to solidify your knowledge of values, variables, operators, and types.

Solution Description

For each of the comments below, write the specified Python code. You may do this in the Python interactive shell or by creating a text file that you run from the command line or import into an interactive Python shell (which runs the code). You could copy the comments below and copy them into a text file with a .py extension.

# Assign the value 3 to the variable a. What is the type of a?
# How do you know the value of a?



# Assign the value 4 to the variable b.



# Assign the result of dividing a by b to the variable d.
# What is the type of d?



# Assign the result of dividing a by b to the variable e using *integer* division.
# What is the type of e?



# Assign the result of calculating the remainder of a `div` b to the variable f,
# where `div` means integer division.
# Hint: this operation is known as `mod` or "modulus".



# If the int values [0,7) (0, 1, 2, 3, 4, 5, 6) refer to Monday through Sunday,
# and today is Monday, what day of the week will it be in 999 days?



# Assign the result of the sum a squared plus b squared to the variable c.



# Assign the string value "foo" to the variable x.



# Assign the string value "fighter" to the variable y.



# Assign the value of x + y to the variable z. What is the value of z?



# Add 1 to z. What happens?