+ 1
Can't seem to get past the Halloween candy test case 3,4&5
Halloween candy issues... What am I missing out?
15 Antworten
+ 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)
...
+ 8
Who knows?? You need to post your code and the challange description before we can help with anything
+ 6
And tag the language you are doing.
Make sure you aren't "hard coding" to get the answers.
+ 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
+ 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.
+ 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 🙂
+ 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 ... ☺️
+ 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.
+ 1
houses = int(input())
if houses >= 3:
dollar = 2 / houses
percentage = round(100 * dollar)
print(percentage)
+ 1
I wrote it in python
+ 1
First two test cases turn out correct, but the rest are wrong and I can't see them cause they're locked
+ 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.
+ 1
import math
houses = int(input())
#your code goes here
chance = (lambda x : math.ceil(2/x*100))(houses)
print(chance)
+ 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))
+ 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.