# Can't seem to get past the Halloween candy test case 3,4&5

9/21/2022 9:28:06 AM

Reliable Used Clothes15 Answers

New AnswerReliable Used Clothes , it is just a small modification. do not use // for division as mentioned. use the ceil() rounding from math module instead of round() function: from math import ceil ... percentage = ceil(100 * dollar) ...

Who knows?? You need to post your code and the challange description before we can help with anything

And tag the language you are doing. Make sure you aren't "hard coding" to get the answers.

Solo , we get different results between *your* rounding method and the *ceil()* function when input is 8 ? rounding method before rounding after rounding -------------------------------------------------------------------------------------------- *solo formula* 25.5 26.0 *ceil* 25.0 25.0

Solo , my recommendation is: > if there is a need for functions, and if there are functions from trusted sources available, use them instead of re-inventing the wheel by doing your own try. this is especially true for mathematical functions.

That was the answer! Thanks Lothar It was round up... Not just round... That's why ceil was necessary Thank you all for your input π

Lothar, thanks for telling me, but I looked that all the tests were successful and did not fix it, although logically it should be 0.49, I hope now everything will work flawlessly ππ In general, SoloLearn developers have another minus. Not only did they mess up the task, but also the testing was not complete ... βΊοΈ

You go trick or treating with a friend and all but three of the houses that you visit are giving out candy. One house that you visit is giving out toothbrushes and two houses are giving out dollar bills. Task Given the input of the total number of houses that you visited, what is the percentage chance that one random item pulled from your bag is a dollar bill? Input Format An integer (>=3) representing the total number of houses that you visited. Output Format A percentage value rounded up to the nearest whole number.

houses = int(input()) if houses >= 3: dollar = 2 / houses percentage = round(100 * dollar) print(percentage)

First two test cases turn out correct, but the rest are wrong and I can't see them cause they're locked

Try dollar = 2//houses See if that gives you a different rounding result. Let me know π And yeah, they always don't show many of the cases so the programmer writes better code to work in "all" situations, not just the a code to produce an end result. Can you imagine if the task was "add 2 numbers together" and the only answer they needed was 4. The programmer could simply write "print("4")" and it would meet the requirement of the end of the task.

import math houses = int(input()) #your code goes here chance = (lambda x : math.ceil(2/x*100))(houses) print(chance)

You can do without an additional library π: houses = int(input()) if houses >= 3: dollar = 2 / houses percentage = round(100 * dollar + 0.49) print(percentage) ALI Moussa Kadjalla π houses = int(input()) #your code goes here print(round(2/houses*100+.49))

Lothar , maybe you are right, but in order to study programming and fully understand it, I would recommend, on the contrary, if possible, write everything yourself, and even more so, resort to using third-party libraries as rarely as possible. Of course, we are not talking about large projects.