Lab 2: 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.1. Write an integer literal in the box below:

[ ]:

1.2. Write a string literal in the box below:

[ ]:

1.3. Write a floating point number literal in the box below:

[ ]:

1.4. Write a boolean literal in the box below:

[ ]:

1.5. Write Avogadro’s Number as a literal.

[ ]:

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

[ ]:

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

[ ]:

Part 2: Operators

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

[ ]:

2.2. Write a program that multiplies 234.4 by 5.

[ ]:

2.3. Write a program that determines if 45.6 is less than 34.5

[ ]:

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

[ ]:

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

[ ]:

2.6. 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.

[ ]:

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

[ ]:

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

[ ]:

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

[ ]:

Part 3: Printing

3.1. Print a String

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

Hello Python World!

[ ]:

3.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.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

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

[ ]:
a = 12.3
b = 6.4

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

[ ]:

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

[ ]:

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

[ ]:

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

[ ]:

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

[ ]:

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

[ ]:

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

[ ]:

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

[ ]:

4.10. Mad Lib!

Write a program that uses variables to play the madlib that’s pictured.

Mr-Bubble-Madlib.jpg

The starer shows you the variables to hold the blanks in the Mad Lib.

[ ]:
adjective1 = ""
verb1 = ""
noun1 = ""
adjective2 = ""
noun2 = ""
verb2 = ""
number1 = ""
adjective3 = ""