Whole Test Case | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Whole Test Case

I'm having troubles for the code of Halloween I visit at least 3 houses and 2 of them give me a dollar. So I have to calculate the percentage of that depending the number of houses. For equal and bigger than 3 the code is running well. In the other cases not. houses = int(input()) if houses>=3: percentdollars=round((2/houses)*100) print(percentdollars) else: if houses==2: percentdollars=round((1/houses)*100) print(percentdollars)

4th Apr 2021, 12:29 AM
Felipe Osorio
Felipe Osorio - avatar
20 Answers
+ 3
Output should be rounded up to the nearest integer. So you need to use ceil() instead of round () import math houses = int(input()) if houses>=3: percentdollars=math.ceil((2/houses)*100) print(percentdollars) else: if houses==2: percentdollars=math.ceil((1/houses)*100) print(percentdollars)
4th Apr 2021, 2:28 AM
Simba
Simba - avatar
+ 2
Yup
4th Apr 2021, 12:47 AM
Felipe Osorio
Felipe Osorio - avatar
+ 2
Idkn where I got 200 houses, but code is worked 🤭
4th Apr 2021, 1:06 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Hi! Its Halloween candy task?
4th Apr 2021, 12:38 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
don't we have to take 200 houses into account?
4th Apr 2021, 12:48 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Just say the condition that I mentioned right up.
4th Apr 2021, 12:52 AM
Felipe Osorio
Felipe Osorio - 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. Sample Input 4 Sample Output 50
4th Apr 2021, 12:53 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Yes
4th Apr 2021, 12:54 AM
Felipe Osorio
Felipe Osorio - avatar
+ 1
I can lead you to the solution of four tests. one test does not pass and I have
4th Apr 2021, 12:55 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Test Case 1 and 2 are solved but I can't see what I'm missing to solve the other Test Cases
4th Apr 2021, 12:57 AM
Felipe Osorio
Felipe Osorio - avatar
+ 1
I have two codes that fail test #4. where do we start?
4th Apr 2021, 12:58 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
How's structured your code?
4th Apr 2021, 12:59 AM
Felipe Osorio
Felipe Osorio - avatar
+ 1
houses = int(input()) #your code goes here percent = 200 // houses if houses > 200: print(1) elif houses % 2 == 0: print(percent) else: print(percent + 1)
4th Apr 2021, 1:05 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Thanks
4th Apr 2021, 1:09 AM
Felipe Osorio
Felipe Osorio - avatar
+ 1
Thanks? You pass all tests?
4th Apr 2021, 1:10 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
your code passes only two tests
4th Apr 2021, 12:57 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
import math houses = int(input()) ratio = 200 / houses print (math.ceil( ratio )) Simple code
5th Apr 2021, 5:33 AM
Atul Singh
Atul Singh - avatar
0
Hi.
5th Apr 2021, 12:17 PM
tusher
tusher - avatar
0
i m. tusher. nice. too meet you. bro
5th Apr 2021, 12:18 PM
tusher
tusher - avatar
0
Test
23rd Sep 2021, 12:29 PM
Bnn