Programming Assignment 1
-
(25 points) Problem 2.5 of the book.
Calculate Tips.
Write a program that reads the subtotal and the gratuity rate, then computes
the gratuity and total. For example, if the user enters
10
for a subtotal and15%
for gratuity rate, the program displays$1.5
as gratuity and$11.5
as total.- Name the file and program
ch02_pr05.py
. - Example execution
(
python3 ch02_pr05.py
on MAC andpy -3 ch02_pr05.py
on Windows) user provides input:
Enter the subtotal and a gratuity rate: 10, 15
The gratuity is $1.50 and total is $11.50 - Example execution
(
python3 ch02_pr05.py
on MAC andpy -3 ch02_pr05.py
on Windows) user provides input:
Enter the subtotal and a gratuity rate: 15.69, 15
The gratuity is $2.35 and total is $18.04
- Name the file and program
-
(25 points) Problem 2.7 of the book.
Find the number of years and days.
Write a program that prompts the user to enter the minutes (e.g., 1 billion)
and displays the number of years and days for the minutes. For simplicity,
assume a year has 365 days.
- Name the file and program
ch02_pr07.py
. - Example execution
(
python3 ch02_pr07.py
on MAC andpy -3 ch02_pr07.py
on Windows) user provides input:
Enter the number of minutes: 1000000000
1000000000 minutes is approximately 1902 years and 214 days
- Name the file and program
-
(25 points) Problem 2.9 of the book.
Science: wind-chill temperature.
How cold is it outside? The temperature alone is not enough to provide the
answer. Other factors including wind speed, relative humidity, and sunshine
play important roles in determining coldness outside. In 2001, the
National Weather Service (NWS) implemented the new wind-chill temperature to
measure the coldness using temperature and wind speed. The formula is
twc = 35.74 + 0.6215ta - 35.75v0.16 + 0.4275tav0.16
whereta
is the outside temperature in degrees Fahrenheit andv
is the speed measured in miles per hour.twc
is the wind-chill temperature. The formula cannot be used for wind speeds below 2 mph or temperatures below -58°F or above 41°F.
Write a program that prompts the user to enter a temperature between -58°F and 41°F and a wind speed greater than or equal to 2 and displays the wind-chill temperature.- Name the file and program
ch02_pr09.py
. - Example execution
(
python3 ch02_pr09.py
on MAC andpy -3 ch02_pr09.py
on Windows) user provides input:
Enter the temperature in Fahrenheit between -58 and 41: 5.3
Enter the wind speed (>=2) in miles per hour: 6
The wind chill index is -5.5671
- Name the file and program
-
(25 points) Find Light Intensity.
Implement a program on the GoPiGo that finds the light color 1 meter away
from the start of the robot. Report this RGBA reading in integer form
(values between 0 and 255). After reading the color, return the robot back
to its starting location. While the robot is moving and collecting the
reading have both the right and left LEDs turned on. Upon completion, the
robot should turn off its left and right LEDs. Note,
that if one of the LEDs does not turn on, the robot itself may be broken,
not your code.
- Name the file and program
find_color.py
. - Use the
turn_degrees
anddrive_cm
to move the robot. - Example execution
(
cat find_color.py | ssh pi@gopigoXX python3 -u
on MAC andtype find_color.py | ssh pi@gopigoXX python3 -u
on Windows, remember to use the correct hostname) user provides input (output may vary):
The color in RGBA is ( 240, 220, 235, 180 ).
Finished returning to original position. - Create a file
find_color.txt
. In this file, please answer the following questions:- Why does the robot not perfectly return to its starting position?
- Can you brainstorm any solution?
- Name the file and program
-
Bonus.
(10 points) Problem 3.5 of the book.
Geometry: area of a regular polygon.
A regular polygon is an n-sided polygon in which all sides are of the same
length and all angles have the same degree (i.e., the polygon is both
equilateral and equiangular). The formula for computing the area of a
regular polygon is
Area = (n*s2)/(4*tan(π/n))
Heres
is the length of a side. Write a program that prompts the user to enter the number of sides and their length of a regular polygon and displays its area. Please format the output to be in scientific notation with six significant digits after the decimal place.- Name the file and program
ch03_pr05.py
. - Example execution
(
python3 ch03_pr05.py
on MAC andpy -3 ch03_pr05.py
on Windows) user provides input:
Enter the number of sides: 5
Enter the side length: 6.5
The area of the polygon is 7.269017e+01
- 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).