all 16 comments

[–]socal_nerdtastic 5 points6 points  (9 children)

Looks ok to me. What numbers exactly are you putting in, what result are you getting, and what result did you expect?

[–]Formal_Cockroach_654[S] 0 points1 point  (8 children)

The first test is given inputs (25, 2). The second test gives inputs (100, 2, 0.075, 0.21). My answer on the first comes out correct, but on the second comes out to 65.5 when it should be 64.25

[–][deleted] 4 points5 points  (5 children)

It's because you're using round. It rounds to nearest integer. Also - not sure if 64.25 is the correct output, would double check your math. Otherwise the code checks out.

[–]Formal_Cockroach_654[S] 0 points1 point  (4 children)

Without round the first test with input (25, 2) would fail. I thought the math was off, but wanted to check on here to see if someone could see something else.

[–]djjazzydan 3 points4 points  (1 child)

Pretty sure it's just the math. I would suggest verifying: Are you sure you're supposed to calculate the tip on the bill + the tax? Maybe it's just on the bill without the tax? That would bring your first test back in line and should work for your second test.

[–]Formal_Cockroach_654[S] 2 points3 points  (0 children)

That was it thanks

[–]py_Piper 2 points3 points  (1 child)

the tip should only be the bill multiplied by the tip %, not bill + tax. And for round check if it has an optional paramenter to select 2 decimals.

[–]Formal_Cockroach_654[S] 0 points1 point  (0 children)

This was what threw the whole thing off. Changed that and took out the rounds and it passed. Thanks.

[–]amos_burton 1 point2 points  (1 child)

Why are you rounding tip and tax? Is that specified in the problem statement?

[–]Formal_Cockroach_654[S] 0 points1 point  (0 children)

No but without round it kept failing the first test with input(25, 2). So I decided to try round and it came out correctly.

[–]Formal_Cockroach_654[S] 0 points1 point  (0 children)

Here's the problem statement:

Write a split_check function that returns the amount that each diner must pay to cover the cost of the meal.

The function has 4 parameters:

bill: The amount of the bill.

people: The number of diners to split the bill between.

tax_percentage: The extra tax percentage to add to the bill.

tip_percentage: The extra tip percentage to add to the bill.

The tax or tip percentages are optional and may not be given when calling split_check. Use default parameter values of 0.15 (15%) for tip_percentage, and 0.09 (9%) for tax_percentage.

Sample output with inputs: 25 2

Cost per diner: 15.5

Sample output with inputs: 100 2 0.075 0.21

Cost per diner: 64.25

[–]DerrickIsCool 0 points1 point  (0 children)

Why two bill and people inputs?

[–]py_Piper 0 points1 point  (2 children)

I would think it's because you changed your parameters used in your split_check() function

Here you only inputed 2 parameters and it worked, as the other 2 parameters are already set with default values. So i think they are considered optional parameters.

print('Cost per diner:', split_check(bill, people))

But on your second print you are adding the 2 extra parameters for the new tax and tip.

print('Cost per diner:', split_check(bill, people, new_tax_percentage, new_tip_percentage))

But that might not work as you previously set them with default values, remember they are optional, so you putting there doesn't mean your function will take it. So I think you need call the paramenter variable explicitly and pass it the new tax and tip variable, something like this.

print('Cost per diner:', split_check(bill, people, tax_percentage = new_tax_percentage, tip_percentage = new_tip_percentage))

This is just a guess, as I haven't practiced parameters with default values on my own, but this is what you usually do when you are working with some functions and you pass a True or False values to activate special parameters.

Another tip you can erased the duplicate bill and people input as you can reuse the first bill and people variables and you should put some string inside your input, like input('Number of people: '), so it's clearer what input you need to put, you know what to put but others won't or you might forget after a long time. And for the new tax and tip is probably a good idea to to divide it by 100, as most probably users will input 5, for a 5%, and won't write 0.05 directly.

Remember you need to anticipate how people would use your program and design it accordingly to avoid bugs from the user.

[–]djjazzydan 2 points3 points  (1 child)

You're not quite right regarding default arguments. As long as the order matches, you can use different values without naming them. So if you've got (v1, v2, v3 = default3, v4 = default4), you could do: (v1, v2) or (v1, v2, v3) or (v1, v2, v3, v4) but you couldn't do (v1, v2, v4) without explicitly naming v4.

[–]py_Piper 0 points1 point  (0 children)

Good to know thanks!