CS 116: Introduction to Computer Science 2

CS 116 Tutorial 1: Introduction to Python (Module 1)


Reminders: Assignment 01 is due on Wednesday, January 23rd at 10am


  1. Write a Python function create_acct_num that consumes a positive 3-digit number and returns the corresponding 4-digit number, in which the new last digit is remainder when the sum of the digits of the original number is divided by 7. For example, create_acct_num(778) => 7781 because 7 + 7 + 8 = 22 and when 22 is divided by 7, it has remainder of 1
  2. Write a Python function shipping_charges that calculates cost of shipping boxes. The function consumes:
    • a handling charge,
    • the cost per kg for shipping,
    • the weight per box (assumed the same for all boxes), and
    • the number of boxes to ship.
    The function adds in 13% tax, and returns the total cost. shipping_charges(handling, charge_per_kg, weight_per_box, num_boxes) For example, Shipping_charges(10, 0.25, 10, 5) => 25.425 Note that the value returned may not stored exactly. So, your test should not check for an exact value, but rather should check that your answer is very close to the expected value.
  3. The standard deviation of a set of numbers x_i is calculated as the square root of the mean of the sums (x_i - x_mean)^2, where x_mean is the arithmetic mean of the x_i values. For example, the standard deviation of 3.2, 9.8, 6.3, 1.2, 3.3 is 3.00039997 Write a Python function std_dev that consumes five floating point numbers (x1,x2,x3,x4,x5) and returns their standard deviation.
  4. Consider a basic smart phone plan that charges as follows:
    • monthly charge $39.00
    • $0.50 per phone minutes over 200 free "anytime" minutes
    • $5.00 for each part of 150 MB of data over the first 100 MB used.
    For example, if you used 15 minutes of phone calls and 87 MB of data, your charge would be $39.00; if you used 250 minutes of phone calls and 500 MB of data, your charge would be $79.00 ($25.0 extra for the phone calls, and $15.0 extra for data). Write a Python function cell_charge that consumes two Nats (minutes and data) corresponding to the total number of phone minutes used and the amount of data used in a month, and returns the total phone bill for the month, including the basic monthly charge. Do not perform any rounding on the result.

Valid XHTML 1.0 Strict

Last modified on Tuesday, 23 April 2019, at 14:26.