+ 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)
20 Antworten
+ 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)
+ 2
Yup
+ 2
Idkn where I got 200 houses, but code is worked 🤭
+ 1
Hi! Its Halloween candy task?
+ 1
don't we have to take 200 houses into account?
+ 1
Just say the condition that I mentioned right up.
+ 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
+ 1
Yes
+ 1
I can lead you to the solution of four tests. one test does not pass and I have
+ 1
Test Case 1 and 2 are solved but I can't see what I'm missing to solve the other Test Cases
+ 1
I have two codes that fail test #4. where do we start?
+ 1
How's structured your code?
+ 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)
+ 1
Thanks
+ 1
Thanks? You pass all tests?
0
your code passes only two tests
0
import math
houses = int(input())
ratio = 200 / houses
print (math.ceil( ratio ))
Simple code
0
Hi.
0
i m. tusher. nice. too meet you. bro
0
Test