1. Write a program in Python that calculates the area of a rectangle. Use this formula: area = hw. Your program will have in-line documentation (a header and in-line comments). Output your answer in meters. Name your program rect_area.py
2. Write a program in Python that calculates the perimeter of a rectangle. Use this formula: perimeter = 2h + 2w. Your program will have in-line documentation (a header and in-line comments). Output your answer in meters. Name your program rect_perimeter.py
3. Write a program in Python that calculates the area of a triangle. Use this formula: area = ½bh. Your program will have in-line documentation (a header and in-line comments). Output your answer in meters. Name your program tri_area.py
4. Write a program in Python that calculates the velocity of a baseball thrown in space. Use this formula: velocity = d/t. Your program will have in-line documentation (a header and in-line comments). What unit should you use? Name your program velocity_calc.py
5. The value PI is more interesting than 3.14. Python provides support for this in a library called math. Calculate the circumference of a circle. Use this formula: circumference = 2PIr. Use the math library to help you with PI. Your program will have in-line documentation (a header and in-line comments). What unit should you use? Give your program an appropriate name.
To import the math library, try this:
import math #import the math library. THIS MUST BE AT THE TOP OF YOUR CODE.
print(math.pi) #see, math.pi is a VALUE!
6. Convert a temperature given in Fahrenheit to Celsius. Use this formula Celsius = 5/9 (F - 32). Your program will have in-line documentation (a header and in-line comments). What unit should you use? Give your program an appropriate name.
1. How does the round() work in Python? Go back to your first problems, and make the output more human friendly with round(). Take 1 of your solutions to the first set of problems, and implement the round function. Add '_ROUND' to the file name. You can use the round function like this:
round(3.8)
# or
number = 5.9
round(number)
1. When is Easter? The point of this question is to get you to think about variable names. Just reimplement the algorithm I've provided for you. each time you see a variable, try to give it a meaningful name. Look at the formula and guess at what's happening.
Given the year, calculate the day and month of Easter using the following formula. Note the month will be 3 or 4: March or April:
a = year mod 19
b = year div 100
c = year mod 100
d = b div 4
e = b mod 4
f = (8b + 13) div 25
g = (19a + b - d - f + 15) mod 30
h = (a + 11g) div 319
i = c div 4
j = c mod 4
m = (2e + 2i - g - h - j + 32) mod 7
month = (g - h + m + 90) div 25
day = (g - h + m + month + 19) mod 32
Your program will have in-line documentation (a header and in-line comments). Give your program an appropriate name.
2. Distance to the horizon: Given your height from the ground in centimetres, calculate the distance (in km) to the horizon using this formula: D = sqrt (0.126*H). Does Python have a built in ability to calculate a square root? Try to import the math library, then call math.sqrt(). Your program will have in-line documentation (a header and in-line comments). Give your program an appropriate name.
3. Digit Breaker: Given a 3 digit number, split the number into 100's, 10's and 1's. Your program will have in-line documentation (a header and in-line comments). Give your program an appropriate name. For example, given the number 172, your program could output 100, 70, 2 OR 1,7,2.
4. Change Change: Given an amount of change less than 99 cents, calculate how many quarters, dimes, nickels and pennies (pennies still exist in this question!) it would take to total the amount. Your program will have in-line documentation (a header and in-line comments). Give your program an appropriate name.
Summative Evaluation
If you can't see the document, please read: You Do Not Need Permission To View Any Documents.