Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

INSTRUCTIONS

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

Question 1 - Temperature Conversion


Write a Python program that converts temperature in Fahrenheit to Celsius.

To do this conversion, you'll need the formula below:

𝑇𝐶 = 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:

A semicircle is half of a circle


You'll need the round() function to approximate the area and perimeter to 3 decimal places

Question 3- Sum of Interior angles in a regular polygon


A regular polygon is a two-dimensional geometric shape with the following characteristics:

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

The sum of interior is given as:

𝑆𝑢𝑚 = (𝑛 − 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.

Question 4 - Escape Velocity of a Rocket


The escape velocity of a rocket is the minimum velocity that a rocket must achieve to break free from the
gravitational pull of a celestial body, such as a planet or moon, and enter space without falling back. It is a
critical parameter for space missions and is calculated based on the mass and radius of the celestial body.

The formula to calculate the escape velocity ( 𝑣𝑒) of a rocket from a celestial body of mass 𝑀 and radius 𝑅
is given by:

𝑣𝑒 = √⎯2𝐺𝑀
⎯⎯⎯⎯⎯⎯⎯
𝑅
where:

𝐺 is the gravitational constant, approximately equal to 6.67 × 10−11𝑚3 /𝑘𝑔𝑠3


𝑀 is the mass of the celestial body (e.g. a planet or moon) in kilograms.
𝑅 is the radius of the celestial body in meters
The escape velocity varies from one celestial body to another because it depends on the mass and radius of
the body.

Write a Python program to calculate the escape velocity of a rocket from Earth and Mars
respectively.

You'll need the following constants:

𝑀𝐸𝑎𝑟𝑡ℎ = 5.972 × 1024 𝑘𝑔, 𝑅𝐸𝑎𝑟𝑡ℎ = 6.371 × 106 𝑚, 𝑀𝑀𝑎𝑟𝑠 = 6.417 × 1023 𝑘𝑔,
𝑅𝑀𝑎𝑟𝑠 = 3.390 × 106 𝑚
Hints:

You need the math module to use the math.sqrt() function


When including the constants in your code, do not include the units
To write the constants in standard form, an example is shown below:

In [2]: 

import math
G = 6.67E-11

Part B

Challenge 1 - Simultaneous Equations with two unknowns


Simultaneous equations with two unknowns are a system of two equations that contain two variables
(unknowns). The goal is to find the values of these variables that satisfy both equations simultaneously. This
system can be written in general form as follows:

𝐴𝑥 + 𝐵𝑦 = 𝑃...............(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

Challenge 2 - Roots of a Quadratic Equation


A quadratic equation is a second-degree polynomial equation in a single variable. It has the general form:

𝑎𝑥2 + 𝑏𝑥 + 𝑐 = 0
where:

𝑎,𝑏,𝑐 are constants, with a not equal to zero


𝑥 is the variable you are trying to solve for, and it represents the unknown values that satisfy the
equation.

𝑥
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:

You'll need the math library to use the math.sqrt() function


You can solve each root separately as follows:

𝑥1 = −𝑏+√2𝑎𝑏2−4𝑎𝑐 , 𝑥2 = −𝑏−√2𝑎𝑏2−4𝑎𝑐

You might also like