+ 1

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

Halloween candy issues... What am I missing out?

21st Sep 2022, 9:28 AM
Reliable Used Clothes
Reliable Used Clothes - avatar
15 Answers
+ 5
Reliable 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) ...
21st Sep 2022, 7:55 PM
Lothar
Lothar - avatar
+ 8
Who knows?? You need to post your code and the challange description before we can help with anything
21st Sep 2022, 9:32 AM
Slick
Slick - avatar
+ 6
And tag the language you are doing. Make sure you aren't "hard coding" to get the answers.
21st Sep 2022, 10:04 AM
Ausgrindtube
Ausgrindtube - avatar
+ 6
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
24th Sep 2022, 6:09 PM
Lothar
Lothar - avatar
+ 5
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.
25th Sep 2022, 2:54 PM
Lothar
Lothar - avatar
+ 2
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 🙂
22nd Sep 2022, 10:54 AM
Reliable Used Clothes
Reliable Used Clothes - avatar
+ 2
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 ... ☺️
24th Sep 2022, 8:02 PM
Solo
Solo - avatar
+ 1
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.
21st Sep 2022, 3:24 PM
Reliable Used Clothes
Reliable Used Clothes - avatar
+ 1
houses = int(input()) if houses >= 3: dollar = 2 / houses percentage = round(100 * dollar) print(percentage)
21st Sep 2022, 3:25 PM
Reliable Used Clothes
Reliable Used Clothes - avatar
+ 1
I wrote it in python
21st Sep 2022, 3:25 PM
Reliable Used Clothes
Reliable Used Clothes - avatar
+ 1
First two test cases turn out correct, but the rest are wrong and I can't see them cause they're locked
21st Sep 2022, 3:26 PM
Reliable Used Clothes
Reliable Used Clothes - avatar
+ 1
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.
21st Sep 2022, 5:01 PM
Ausgrindtube
Ausgrindtube - avatar
+ 1
import math houses = int(input()) #your code goes here chance = (lambda x : math.ceil(2/x*100))(houses) print(chance)
22nd Sep 2022, 11:26 AM
ALI Moussa Kadjalla
ALI Moussa Kadjalla - avatar
+ 1
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))
23rd Sep 2022, 7:12 AM
Solo
Solo - avatar
+ 1
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.
25th Sep 2022, 4:11 PM
Solo
Solo - avatar