# You must make sure to run all cells in sequence using shift + enter or you might encounter errors
from pykubegrader.initialize import initialize_assignment
responses = initialize_assignment("13_module_q", "week_1", "readings", assignment_points = 9.0, assignment_tag = 'week1-readings')
# Initialize Otter
import otter
grader = otter.Notebook("13_module_q.ipynb")
โ What is a Python Module?#
# Run this block of code by pressing Shift + Enter to display the question
from questions._13_module_q import Question1
Question1().show()
# Run this block of code by pressing Shift + Enter to display the question
from questions._13_module_q import Question2
Question2().show()
# Run this block of code by pressing Shift + Enter to display the question
from questions._13_module_q import Question3
Question3().show()
๐ฆธโโ๏ธ Avengers Mission: Python Modules!#
The Avengers need your coding skills to prepare for their next mission. Your task is to help them with three important calculations using Pythonโs math
module.
Mission Objectives#
Thorโs Task: Calculate the area of Mjolnirโs circular base. The radius is 10 units. Use the formula for the area of a circle:
\(\text{Area} = \pi \times r^2\)
Use the constant
math.pi
and store the result in a variable namedhammer_area
.Iron Manโs Task: Compute the cosine of 45 degrees to optimize his repulsor targeting system.
First, convert 45 degrees to radians using:
\(\text{Radians} = \text{Degrees} \times \frac{\pi}{180}\)
Use the function
math.radians
to handle this conversion.Then, calculate the cosine using
math.cos
.
Store the result in a variable namediron_cosine
.
Captain Americaโs Task: Determine the least common multiple (LCM) of 12 and 18 to synchronize the teamโs communication devices.
First, find the greatest common divisor (GCD) using
math.gcd
.Then, calculate the LCM using the formula:
\(\text{LCM}(a, b) = \frac{|a \times b|}{\text{GCD}(a, b)}\)
Store the result in a variable named
cap_lcm
.
Requirements#
Write a Python program to perform these calculations.
Use the
math
module to simplify your work.Assign the results to the variables
hammer_area
,iron_cosine
, andcap_lcm
.Print the results at the end of your program so the Avengers can see them.
Now, go save the world with your coding skills! ๐
# Add your import statement here
...
def avengers_assemble():
# Thor's hammer base area (circle area formula: ฯrยฒ)
hammer_area = ...
# Iron Man's cosine calculation (convert degrees to radians first)
iron_cosine = ...
# Captain America's LCM calculation
# Find the LCM of 12 and 18
a = 12
b = 18
cap_lcm = ...
return hammer_area, iron_cosine, cap_lcm
# Do not modify the code below this line
# Print results
hammer_area, iron_cosine, cap_lcm = avengers_assemble()
print(f"Mjolnir's base area: {hammer_area}")
print(f"Iron Man's cosine of 45 degrees: {iron_cosine}")
print(f"Captain America's LCM: {cap_lcm}")
grader.check("avengers-mission-modules")
Submitting Assignment#
Please run the following block of code using shift + enter
to submit your assignment, you should see your score.
from pykubegrader.submit.submit_assignment import submit_assignment
submit_assignment("week1-readings", "13_module_q")