Math error in App Lab

A student is making a shopping app in AppLab for her Create Task. Her program code is correct for adding two values however the result is not what you would expect. If she chooses the beach ball ($4.99) and adds anything to it, she gets a crazy amount of decimal places. Two numbers with two decimal places that are added together should not result in as many decimal places as shown in the console log.

Any ideas?

1 Like

This is a great opportunity for you to refer back to the Code.org unit on representing and encoding numbers. Because there are an infinite number of values between any two integer values and our software is forced to use a fixed number of bits to represent numbers, we can’t possibly come close to encoding every possible decimal number. This student’s code demonstrates the loss of precision that is a side effect of representing fractional numbers in binary.

Ok, now how to fix it?
One easy option is to have the student change the prices to be integer values.
Another option is store all of the prices in cents and then convert to dollars and cents when displaying the value in the app. This can be a challenging but satisfying problem for students to solve!

2 Likes

Thanks, @Mitch - I learned something new. :slight_smile:

Too bad @awright that you’re not allowed to share with the student @Mitch’s options on how to fix it (as far as I understand the rules - unless it’s a section she’s not doing the Written Response part about), but the positive side about that is this definitely gives her something to talk about for Written Response 2b (incremental and iterative program development - describe a difficulty). (Although hm, we can’t tell her that either huh… :sweat_smile:)

Thanks for bringing up the interesting problem!

Frank

Or can I? It is a technical problem – and we are allowed to help with that and with directions. So telling her that it is a problem with precision of the language that AppLab uses doesn’t actually do anything outside the “rules” does it?

I agree that it’s okay to explain why it’s doing what it’s doing, but I’m less sure about providing possible solutions. I’m not 100% certain though and I’m not the College Board. :smile:

1 Like

I really wish the College Board would be more explicit with the teacher instructions because a lot is definitely open to interpretation. I don’t see this as a technical problem because I read that to mean something technology related that is preventing the student from completing the work, like problems accessing the CB website or instruction is needed in how to capture video. Although, it is arguable that under the guideline of “Teachers may continue whole class teaching of course content and skills during non-designated time to complete the performance task”, you would be able to teach the class about floating point precision errors and how to avoid them.

The answer to the question is unclear to me but I would err on the safe side and explain that there is nothing in the grading guidelines that takes off points for code that doesn’t work as expected. It’s unfortunate that perhaps the best thing to do is to recommend submitting buggy code but that’s all that I can assume that we’re supposed to do.

1 Like