Programming Assignment 3
-
(25 points) Problem 5.27 of the book.
Compute π.
You can approximate
π
using the following series:
π = 4(1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + … + (-1)i+1/(2i - 1))
Write a program that displaysπ
value fori = 10000, 20000, …, 100000
.- Name the file and program
ch05_pr27.py
. - Example execution
(
python3 ch05_pr27.py
on MAC andpy -3 ch05_pr27.py
on Windows) user provides input:
10000 3.141492654
20000 3.141542654
30000 3.141559320
40000 3.141567654
50000 3.141572654
60000 3.141575987
70000 3.141578368
80000 3.141580154
90000 3.141581542
100000 3.141582654
- Name the file and program
-
(25 points) Problem 5.33 of the book.
Financial application: compute CD value. Suppose you put $10,000 into a CD
with an annual percentage yield of 5.75%. After one month, the CD is worth
10000 + 10000 * 5.75 / 1200 = 10047.92
After two months, the CD is worth
10047.91 + 10047.91 * 5.75 / 1200 = 10096.06
After three months, the CD is worth
10096.06 + 10096.06 * 5.75 / 1200 = 10144.44
and so on.
Write a program that prompts the user to enter an amount (e.g.,10000
), the annual percentage yield (e.g.,5.75
), and the number of months (e.g.,18
) and displays a table as shown below.- Name the file and program
ch05_pr33.py
. - Example execution
(
python3 ch05_pr33.py
on MAC andpy -3 ch05_pr33.py
on Windows) user provides input:
Enter the initial deposit amount: 10000
Enter annual percentage yield: 5.75
Enter maturity period (number of months): 18
Month CD Value
1 10047.92
2 10096.06
3 10144.44
4 10193.05
5 10241.89
6 10290.97
7 10340.28
8 10389.82
9 10439.61
10 10489.63
11 10539.89
12 10590.40
13 10641.14
14 10692.13
15 10743.37
16 10794.84
17 10846.57
18 10898.54
- Name the file and program
-
(25 points) Problem 5.43 of the book.
Math: combinations. Write a program that displays all possible combinations
for picking two numbers from integers
1
to7
. Also display the total number of all combinations.- Name the file and program
ch05_pr43.py
. - Example execution
(
python3 ch05_pr43.py
on MAC andpy -3 ch05_pr43.py
on Windows) user provides input:
1 2
1 3
1 4
1 5
1 6
1 7
2 3
2 4
2 5
2 6
2 7
3 4
3 5
3 6
3 7
4 5
4 6
4 7
5 6
5 7
6 7
The total number of all combinations is 21
- Name the file and program
-
(25 points) 3 Circles.
Implement a program on the GoPiGo that allows the robot to move in a circle
three times. Use
robot.steer(100, 15)
for in total 8 seconds to complete one circuit around a circle (it is ok it isn't exact). However, there is one complicating aspect, whenever a bright light appears (r, g, b components average to a number greater than 0.5), the robot should stop for 1 second. After the pause, the robot should continue its journey of three circles. Take a reading of the light and color sensor every 0.1 seconds.- Name the file and program
circles.py
. - Example execution
(
cat circles.py | ssh pi@gopigoXX python3 -u
on MAC andtype circles.py | ssh pi@gopigoXX python3 -u
on Windows, remember to use the correct hostname) user provides input (output may vary):
No textual output. - Create a file
circles.txt
. In this file, please answer the following questions:- Summarize what you have learned about robotics so far from our problems.
- Name the file and program
-
Bonus.
(10 points) Problem 5.19 of the book.
Display pyramid. Write a program that prompts the user to enter an integer
from
1
to15
and displays a pyramid like below.- Name the file and program
ch05_pr19.py
. - Example execution
(
python3 ch05_pr19.py
on MAC andpy -3 ch05_pr19.py
on Windows) user provides input:
Enter the number of lines: 7
1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
6 5 4 3 2 1 2 3 4 5 6
7 6 5 4 3 2 1 2 3 4 5 6 7
- Name the file and program
General Instructions, Turning in assignments, and Grading
General Instructions
- Name each file and program as listed in the instructions.
- The top of each program should have a comment block where the first line
is your name and following lines are a description of your program.
# Name: Jory Denny
# This program debates Batman vs Superman!
# References:
# - Ref 1. - Any program solution that defines its own function or class must have a
main
function and properly specified entry point into the program, e.g.:
def main():
# Do something
if __name__ == '__main__':
main() - Use proper coding style (described more in Grading below)
- While I support extra research, use of online materials, and collaboration with other students, please ensure the work is your own and you understand all portions of the work you turn in.
- Follow turn-in instructions precisely.
- Failure to complete any of these steps will result in a significant loss of points.
Turn in Instructions
Each assignment will be turned in through GitHub classroom. Please find the link to create a repository at the top of this page, or through this link. Robot problems must be demonstrated by 5pm and assignments must be submitted to GitHub by 11:59pm of the due date. I do not accept any late assignments.
- Soft copy (Online submission)
- Accept the invitation to the classroom assignment, which creates your repository on GitHub.
- Clone this repository, which includes some starting files.
- Add assignment files (stage, commit, push).
- Modify the Coverpage.txt file to provide name, sources, signature of following the honor code, etc. Be sure to stage, commit, and push these changes as well. If you do not fill out the coverpage, I will not grade the assignment.
- After the due date, I will clone your repository and add a grade and comments as necessary. After which you can pull these changes for your records.
Additionally, robotics problems will need to be demonstrated to me. This must be demonstrated to me by 5pm on the due date.
Points
- Each assignment is graded out of 100 points (not including bonus).
- Criteria and point distribution
- If the code is not named precisely or does not execute correctly, -50% on a problem.
- Following instructions and algorithm used to solve the problem, 25% on a problem. Following instructions is extremely important in computer science, train yourself to think like a computer. There are many ways to solve a problem, some may be better or worse than others.
- Stylistic elements of written code,
25% of a problem. Style includes (but is not
limited to):
- Every class, method, and function must be documented with docstrings describing its purpose, formal arguments, and return value.
- Control flow should be documented with intent and purpose of code
- Naming should be descriptive and consistent
- Indenting properly
- Consistent spacing
- Avoiding code duplication
- While I support extra research, use of online materials, and collaboration with other students, please ensure the work is your own and you understand all portions of the work you turn in. If I suspect excessive use of online materials, I will invite you to walk me through your solution. If you are not able to explain the work sufficiently, I will not give credit for that problem.
- If there are any discrepancies in grades please see the instructor during his office hours or by appointment (do not discuss with the lab assistants or graders).