5 total points
Directions¶
- Due: 9/14/2025 @ 11:59 p.m.
- Change the name of your notebook to EX2_FirstLast.ipynb, where First is your first name and Last is your last name.
- For each of the following prompts, write or modify Python code that fulfills the requirements.
Important information to remember¶
- Periodically, you should click File -> Save Notebook
- When you are done working for the day, click File -> Log Out
- When you are finished, download the notebook and upload it to the submission link
- I will reset the notebook and run each code block on its own. You will receive half credit if you rely on a variable from a previous or subsequent code block.
Assigning and printing variables (0.25 pts each)¶
Problem 1¶
Set a variable named a
to the value 10 and print the value associated with variable a
using the variable a
Problem 2¶
Print the math operation 10 + 5
without using any variables
Problem 3¶
Set the result of the operation 10 + 5
equal to a variable named b
and then print value associated the variable b
using the variable b
Problem 4¶
Set a variable named c
equal to 5, and a variable named d
equal to 10; then print the result of the operation c + d
Problem 5¶
Change the following code so the print statement produces the output “12”
e = 10
f = 15
result = e + f
print(result)
25
Using variables in equations (0.25 pts each)¶
Problem 6¶
Implement the linear equation y = mx + b
in Python code. Your slope should be 2, your intersect should be 5, and your x position should be 1.
The output from two print statements should be exactly equal to the following. You must use the variables m
, x
, b
, and y
to print:
m: 2 x: 1 b: 5
The resulting y value is 7
Do not reuse variable definitions from previous problems. Explicitly set the required variables in the following code block.
HINT: Use the error message to find any bugs in your code.
# place your code below this line
# do not change anything below this line
print("m:", m, "x:", x, "b:", b)
print("The resulting y value is", y)
Math operations (0.25 pts each)¶
Use the clues in the print statement text below to change the operations (and only the operations) if needed. The answers you must match are given for each problem.
Problem 7¶
Reproduce the following output exactly: Sum is 4
a = 2
b = 2
print("Sum is", a % b)
Problem 8¶
Reproduce the following output exactly: Difference is -1
a = 1
b = 2
print("Difference is", a * b)
Problem 9¶
Reproduce the following output exactly: Product is 2
a = 1
b = 2
print("Product is", a ** b)
Problem 10¶
Reproduce the following output exactly: Quotient is 0.5
a = 1
b = 2
print("Quotient is", a + b)
Problem 11¶
Reproduce the following output exactly: Exponential is 4
a = 2
b = 2
print("Exponential is", a - b)
Problem 12¶
Reproduce the following output exactly: Remainder is 3
a = 7
b = 4
print("Remainder is", a / b)
Order of operations (0.25 pts each)¶
Problem 13¶
Given the following four equations, add parentheses (and only parentheses) to get a different result each time. Do not change anything else about the equation.
result1 = 1 + 5 * 4 - 2 + 2**2 / 4
result2 = 1 + 5 * 4 - 2 + 2**2 / 4
result3 = 1 + 5 * 4 - 2 + 2**2 / 4
result4 = 1 + 5 * 4 - 2 + 2**2 / 4
print("result1 =", result1)
print("result2 =", result2)
print("result3 =", result3)
print("result4 =", result4)
Problem 14¶
Calculating the mean of 2 or more numbers requires two steps:
- Find the sum of the numbers
- Divide by the count of numbers
The equation below is your first try. Is this correct? If not change it so it is correct using order of operations.
a = 1
b = 2
c = 3
d = 4
e = 5
mean_first_try = a + b + c + d + e / 5
print(mean_first_try)
Printing text and inserting “comments”¶
Problem 15 (0.25 pts)¶
Change the following code so it prints “5” instead of “10” using a Python comment and only a Python comment.
a = 5
a = 10
print(a)
Problem 16 (0.25 pts)¶
Print the string “explicit” using the print statement
Problem 17 (0.25 pts)¶
Set the string “implicit” equal to a variable named example
, and then print the value of example
using example
Problem 18 (0.75 pts)¶
Use one print statment to create a formatted message equal to the following:
“The temperature is 80 and the dewpoint is 70”
You must use a variable named temp
for the temperature and dew
for the dewpont in the print statement.