Lab: Literals, Operators, Variables and Print

We covered a lot today! This lab will help you build skill in doing the essential programming tasks of using literals, operators and variables. Along the way you’ve used the print() function a lot. The last part of the lab will give you more practice with print(), an essential funtion seeing what your program is doing!

Part 1: Literals

In the cells provided write enter the literals that each question asks for. Run the cell to make sure that your literal is correct.

1. Integer

Write an integer literal in the box below:

[ ]:

2. String

Write a string literal in the box below:

[ ]:

3. Float

Write a floating point number literal in the box below:

[ ]:

4. Boolean

Write a boolean literal in the box below:

[ ]:

5. Scientific Notation

Write Avogadro’s Number as a literal.

[ ]:

6. String

Write your full name in the box below as a string literal.

[ ]:

7. Data Type

In the box below use the type() function to determine the type of True

[ ]:

Part 2: Operators

1. Modulus

Write a program that computes and prints the value of 127 modulus 34.

[ ]:

2. Multiply

Write a program that multiplies 234.4 by 5.

[ ]:

3. Compare Numbers

Write a program that determines if 45.6 is less than 34.5

[ ]:

4. Multiply and Compare

Write a program that determines if 4.2 times 45 is less than or equal to 345.3

[ ]:

5. Days

Write a program that computes how many days there are in 20 years.

[ ]:

6. Mileage

Write a program that computes how far your car can go if it gets 34.5 miles per gallon and has a 11.5 gallon tank.

[ ]:

7. How Much Gas

Write a program that computes how much gas you need to go 200 miles if your car gets 34.5 miles per gallon.

[ ]:

8. A Lot of You

Write a program that prints your name 100 times using the * operator.

[ ]:

2.9. Concatenation

Write a program that concatenates three strings together using the + operator.

[ ]:

Part 3: Printing

1. Print a String

Write a program in the box below that prints the following:

Hello Python World!

[ ]:

2. Print a Poem

Write one or more print statements that print this Pablo Neruda poem.

I do not love you except because I love you;
I go from loving to not loving you,
From waiting to not waiting for you
My heart moves from cold to fire.

I love you only because it's you the one I love;
I hate you deeply, and hating you
Bend to you, and the measure of my changing love for you
Is that I do not see you but love you blindly.

Maybe January light will consume
My heart with its cruel
Ray, stealing my key to true calm.

In this part of the story I am the one who
Dies, the only one, and I will die of love because I love you,
Because I love you, Love, in fire and blood.
[ ]:

3. Print a Poem with Variables

Take the code in the previous cell and paste it into the cell below. Change your print statement or statements to replace the word “love” with the variable word.

[ ]:
word = "love"

print ("I am printing the poem, replacing love with", word)

# Put your poem code below this line.

Part 4: Using Variables

1. Add Variables

Add the two variables named a and b. Start with the code already in the cell.

[ ]:
a = 12.3
b = 6.4

2. Print Variables

Use the print function to print the product of the variables a and b

[ ]:

3. Print Difference

Use the print function to print the difference between of the variables a and b

[ ]:

4. Print True or False

Use the print function to print True if a equals b. False otherwise.

[ ]:

5. Print True or False

Use the print function to print True if a is less than b. False otherwise.

[ ]:

6. Print True or False

Use the print function to print True if a is greater than or equal to b. False otherwise.

[ ]:

7. Print Formula

Use the print function to print True if a times 100 is less than b. False otherwise.

[ ]:

8. Print Formula 2

Use the print function to print True if a modulus 100 is less than b. False otherwise.

[ ]:

9. Print Formula 3

Use the print function to print True if a modulus 100 is less than b time 10. False otherwise.

[ ]: