Lecture 2 Coding Assignment - Jupyter Notebook
Lecture 2 Coding Assignment - Jupyter Notebook
You are required to provide the codes for only three problems in part A. Part B contains two challenge
problems which you are advised to try out although it won't be graded but something similar might be given
in the comprehensive exam.Ensure your code runs on your device without errors before turning it in. Finally,
you are permitted to use any portion of my code as a guide.
Part A
𝑇𝐶 = 59 (𝑇𝐹 − 32)
Question 2 - Semicircle
Write a Python program that calculates the area and perimeter to 3 decimal places of a semicircle
given the radius.
Hints:
Equal Sides: In a regular polygon, all sides have the same length. This means that if you were to
measure any pair of adjacent sides, they would have the same length.
Equal Angles: All interior angles of a regular polygon are congruent, which means they have the same
measure. If you were to measure the interior angles of a regular polygon, each angle would have the
same value.
Symmetry: A regular polygon has rotational symmetry, meaning you can rotate it by a certain angle
(usually the central angle) and it will align with itself. The number of times you can rotate a regular
polygon to make it align with itself is equal to the number of its sides.
Write a Python program that calculates the sum of interior angles in an n-sided polygon given the
number of sides
𝑆𝑢𝑚 = (𝑛 − 2) × 180𝑜
where n is the number of sides
NOTE: Cast the input() into an int type before calculating the sum. The sum of angles must be an integer.
The formula to calculate the escape velocity ( 𝑣𝑒) of a rocket from a celestial body of mass 𝑀 and radius 𝑅
is given by:
𝑣𝑒 = √⎯2𝐺𝑀
⎯⎯⎯⎯⎯⎯⎯
𝑅
where:
Write a Python program to calculate the escape velocity of a rocket from Earth and Mars
respectively.
𝑀𝐸𝑎𝑟𝑡ℎ = 5.972 × 1024 𝑘𝑔, 𝑅𝐸𝑎𝑟𝑡ℎ = 6.371 × 106 𝑚, 𝑀𝑀𝑎𝑟𝑠 = 6.417 × 1023 𝑘𝑔,
𝑅𝑀𝑎𝑟𝑠 = 3.390 × 106 𝑚
Hints:
In [2]:
import math
G = 6.67E-11
Part B
𝐴𝑥 + 𝐵𝑦 = 𝑃...............(1)
𝐶𝑥 + 𝐷𝑦 = 𝑄...............(2)
where A, B, C, D, P, and Q are constants
𝑥 𝑦
The unknowns ( , and ) can be determined using the equations below:
𝑥 = 𝑃×𝐷−𝐵×𝑄
𝐴×𝐷−𝐵×𝐶
𝑦 = 𝐴×𝑄−𝐶×𝑃
𝐴×𝐷−𝐵×𝐶
Write a Python program that can solve any simultaneous equation with two unknowns given the
different constants
𝑎𝑥2 + 𝑏𝑥 + 𝑐 = 0
where:
𝑥
To solve a quadratic equation for , you can use the quadratic formula:
𝑥 = −𝑏±√2𝑎𝑏2−4𝑎𝑐
Write a Python program that calculates the two roots of a quadratic equation given the constants
Hint:
𝑥1 = −𝑏+√2𝑎𝑏2−4𝑎𝑐 , 𝑥2 = −𝑏−√2𝑎𝑏2−4𝑎𝑐