Programming Assignment 1


  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 and 15% 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 and py -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 and py -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
  2. (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 and py -3 ch02_pr07.py on Windows) user provides input:
      Enter the number of minutes: 1000000000
      1000000000 minutes is approximately 1902 years and 214 days
  3. (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

    where ta is the outside temperature in degrees Fahrenheit and v 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 and py -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
  4. (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 and drive_cm to move the robot.
    • Example execution (cat find_color.py | ssh pi@gopigoXX python3 -u on MAC and type 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?
  5. 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))

    Here s 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 and py -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


General Instructions, Turning in assignments, and Grading

General Instructions

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.

Additionally, robotics problems will need to be demonstrated to me. This must be demonstrated to me by 5pm on the due date.

Points