Docsity

CS 1301 Pair Programming Assignment 2: Conversions and Tip Calculator - Prof. Jay Summet, Study notes of Computer Science

Toggle sidebar
bg1
CS 1301
Pair Homework 2 – Conversions/Tip Calculator
Due: Friday, Sep 10th, before 6 PM
Out of 100 points
Files to submit: 1. hw2.py
You will be writing several functions, but they will all be saved in one file: hw2.py. Please save all of
the functions in this one file or you will lose points. This is a pair programming problem! You are
expected to work with the person you have been pared with in class, and you are both responsible for
submitting the exact same code to T-Square. Your pair may collaborate with other students in this class.
Collaboration means talking through problems, assisting with debugging, explaining a concept, etc.
You should not exchange code or write code for other pairs. Collaboration at a reasonable level will
not result in substantially similar code. For pair programming assignments, you and your partner should
turn in identical assignments.
For Help:
- TA Helpdesk – Schedule posted on class website.
- Email TAs
Notes:
Don’t forget to include the required comments and collaboration
statement (as outlined on the course syllabus).
Do not wait until the last minute to do this assignment in case you run into
problems.
If you find a significant error in the homework assignment, please let a TA know
immediately.
Part 1 – Conversions (45 pts)
Section A – Mass (15 pt s)
For part A, you will write a function called mass() which takes in a value in
kilograms and coverts that value into stones. For reference, there are 0.157
stones (yes, that's a real unit!) in 1 kilogram. Please return the value. Save this
function in your hw2.py file as well.
Sample Output:
>>> mass(4)
0.628
>>> mass(8)
1.256
Section B – Volume (15 pts)
In this section, you will need to convert volumes. There are 2.11 US pints in one
liter.
pf3

Partial preview of the text

Download CS 1301 Pair Programming Assignment 2: Conversions and Tip Calculator - Prof. Jay Summet and more Study notes Computer Science in PDF only on Docsity!

CS 1301

Pair Homework 2 – Conversions/Tip Calculator

Due: Friday, Sep 10

th

, before 6 PM

Out of 100 points

Files to submit: 1. hw2.py You will be writing several functions, but they will all be saved in one file: hw2.py. Please save all of the functions in this one file or you will lose points. This is a pair programming problem! You are expected to work with the person you have been pared with in class, and you are both responsible for submitting the exact same code to T-Square. Your pair may collaborate with other students in this class. Collaboration means talking through problems, assisting with debugging, explaining a concept, etc. You should not exchange code or write code for other pairs. Collaboration at a reasonable level will not result in substantially similar code. For pair programming assignments, you and your partner should turn in identical assignments. For Help:

  • TA Helpdesk – Schedule posted on class website.
  • Email TAs Notes:  Don’t forget to include the required comments and collaboration statement (as outlined on the course syllabus).  Do not wait until the last minute to do this assignment in case you run into problems. If you find a significant error in the homework assignment, please let a TA know immediately.

Part 1 – Conversions (45 pts)

Section A – Mass (15 pt s)

For part A, you will write a function called mass() which takes in a value in kilograms and coverts that value into stones. For reference, there are 0. stones (yes, that's a real unit!) in 1 kilogram. Please return the value. Save this function in your hw2.py file as well. Sample Output:

mass(4)

mass(8)

Section B – Volume (15 pts)

In this section, you will need to convert volumes. There are 2.11 US pints in one liter.

Write a function called volume() that takes in a value in liters and converts it to US pints. Since we want to know what we’re dealing with, print the value out with a nice little sentence explaining the conversion that just happened. Please print the values to 2 decimal places. See the sample output below. Save this function in your hw2.py file as well. Sample Output:

volume(1) There are 2.11 US pints in 1.00 liters volume(4) There are 8.44 US pints in 4.00 liters

Section C – Monkeys (15 pts)

Just like the previous two problems, it’s conversion time. One average spider monkey is equal to 37.62533333333 hockey pucks. Seriously. Write a function called monkeys() that takes in a number of monkeys and prints out the resultant conversion into hockey pucks. Please round the number of hockey pucks to 4 decimal places. See the sample output for more clarification. Save this function in your hw2.py file as well. Sample Output:

monkeys(3) There are 112.8760 hockey pucks in 3.000000 average spider monkeys monkeys(11.57) There are 435.3251 hockey pucks in 11.570000 average spider monkeys Source for the conversion factor: http://www.weirdconverter.com/ You should totally go there and play around with conversions that don’t make any sense. Impress your professors! Entertain your friends! Dazzle your family!

Part 2 – It’s Math Time! (55 points)

So you’ve been up all night playing Rock Band™ with your friends. Well, rocking out hardcore always makes one tired, so you decide to go grab some food. It being nearly 3 am, the only place is the great institution of Waffle House. However, you’re spent from a night of constant awesomeness, and realize you just won’t be able to compute the appropriate tip amount for the waitress in your head. For some reason, though, the part of your brain that writes Python functions is super focused and ready to go, so you decide to whip out your laptop and write a Python program to handle the tip calculations for you. (Yes, you brought your laptop to Waffle Hours with you. You are a Tech student, after all.) You program will also need to be able to handle tax. -Write a function called tipCalculator() that prompts the user for the bill amount and the percent that they want to leave for the tip. Do not include the dollar sign or percent sign when entering the numbers! -Calculate the tax ( always 7.8% ), the tip (percent of bill amount, excluding tax), and the total bill. -Remember to divide the percentages by 100 when multiplying. Here, it is important to remember how Python handles division. -You are expected to round the your tip to the next dollar by use of the math.ceil() function. Basically, math.ceil() always rounds the number up to the next integer. Do not forget to import math when using functions from the math module!