Docsity

CS 1301 Fall 2008 Homework 3: Tip Calculator, Textbook Pricing, and Birthday Planner, Assignments of Computer Science

Toggle sidebar
bg1
CS 1301 – Fall 2008
Homework 3 – Maths R Us
Due: Friday, September 12th, at 6 PM
Out of 100 points
Files to submit: 1. hw3.py
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 – Tip Calculator (30 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 files 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.
You program will also need to be able to handle tax.
-Write a function 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 8%), the tip (percent of bill amount, excluding tax), and the
total bill.
-Remember to divide the percentages by 100 when multiplying.
-You are expected to round the your tip to the next dollar by use of the math.ceil()
pf3
pf4
pf5

Partial preview of the text

Download CS 1301 Fall 2008 Homework 3: Tip Calculator, Textbook Pricing, and Birthday Planner and more Assignments Computer Science in PDF only on Docsity!

CS 1301 – Fall 2008

Homework 3 – Maths R Us

Due: Friday, September 12th, at 6 PM

Out of 100 points

Files to submit: 1. hw3.py 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 – Tip Calculator (30 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 files 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.

You program will also need to be able to handle tax.

-Write a function 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 8%), the tip (percent of bill amount, excluding tax), and the total bill.

-Remember to divide the percentages by 100 when multiplying.

-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.

For example:

math.ceil(4.51)

math.ceil(6.7)

math.ceil(3.2)

-Round the tax to the nearest cent by use of string formatting.

Sample output:

tipCalculator() How much is the bill before tax and tip? 7. What percent tip do you want to leave? 15 Tax is $0. Tip is $2. Total is $10.

Save your function into a file called hw3.py. Remember to name your file exactly!

Part 2 – Textbook Pricing (40 Points)

Well, now that the fun Rock Band times are over, you must begrudgingly start on your many homework assignments that have been piling up. However, since you’ve been in video game mode, you haven’t even bought books yet! Guess it’s time to head to the bookstore.

You will need to create three functions for this assignment. The first function is our main

function, called textbook(), taking no parameters and returning nothing. Upon running textbook() the user should be prompted for the option to BUY a textbook or SELL back a textbook (“b” for buy, and “s” for sell). Also, since good economics is important, the program should also assume (prompt for and appropriately store) that the user has done

some research and has an estimate cost of the book s/he is trying to buy or sell back.

Unfortunately, the textbook stores aren't as nice as one would hope and add 10% to your estimated cost if the price is less than fifty dollars, 15% if your estimated cost is between fifty (inclusive) and one hundred dollars, and adds a whopping 20% to the estimated cost if the price is over one hundred dollars when you're trying to buy a book. When selling back a book, the same discounts are true, but reversed (ex. if you were trying to sell back

takes in two parameters, name (as a string) and currentAge (should be an integer). However, you’ll need to remember to add one to their current age somewhere in

your function, as that is how old your friend will be turning on their birthday! Where to go to celebrate will be based on this age.

Age Cut-offs:

-If the new age is less than or equal to 6, take the person to Chuck-E-Cheese

-If the new age is greater than 6 but less than or equal to 17, take the person to the mall. -If the new age is greater than 17 but less than or equal to 26, take the person to The Vortex. -If the new age is greater than 26 but less than or equal to 50, take the person salsa dancing. -If the new age is greater than 50, go to the Opera.

We also want to check and see if the new age is a special birthday, meaning, the birthday person is turning 10, 20, 30, etc. If so, we want to remind the user to get a card for the celebration. Again, save this function in your hw3.py file!

Sample Output:

birthday("Melody", 5) For the 6 year old, take Melody to Chuck-E-Cheese!! birthday("Sam", 19) For the 20 year old, take Sam to The Vortex!! Also, for Sam's 20th birthday, be sure to get a special card. birthday("Steve", 46) For the 47 year old, take Steve salsa dancing!!

Part 4 – Grading Breakdown

#1 – Tip Calculator File Named Correctly…………………….5 points Gets input from user……………………...5 points Tax Calculated and Displayed Correctly...5 points Tip Calculated and Displayed Correctly…5 points Total Calculated and Displayed Correctly.5 points Uses the math.ceil() function…………….5 points

Total: 30 points #2 – Textbook Pricing buyString and sellString functions correct……...10 points (5 for each one) Correctly adjusts the price………………………10 points textbook() function conditionals are correct…….15 points Casts the estimated cost/does math with floats….5 points Total: 40 points

#3 – Birthday Planner Correctly calculates new age of the person…………….5 points Age conditions are correct………………………...…..10 points Print statements are correct…………………………....10 points Prints card reminder for special birthdays…………….5 points Total: 30 points

Grand Total: 100

As always, you can earn up to 5 points bonus for going beyond the scope of the homework and doing something nifty keen. [Hey, the 1950s called, they want their slang back.]

Part 5 – Turning it in

Please save all 5 functions (tipCalculator, textbook, buyString, sellString, and birthday) into ONE file, hw3.py! You will lose 10 points if you submit each file separately!

Submit hw3.py to T-Square by Friday, September 12th^ at 6pm. You can turn it in before Monday, September 15th^ for 10% off. We will NOT accept any submissions after Monday at 6pm!

Portions adapted from the Summer 2007 Homework

Written by Sam Asghari and Melody Nailor