+ 17

Halloween Candy

Could someone help me with this problem? houses = int(input()) #your code goes here dollar = 2/houses*100 print(round(dollar)) It works only for the first two cases. The other ones are locked for me, so I don't know what's wrong.

31st Jan 2020, 10:12 PM
Diana Oršolyová
Diana Oršolyová - avatar
20 Réponses
+ 28
Output Format A percentage value rounded up to the nearest whole number. round up is done with. math.ceil() not round()
31st Jan 2020, 11:03 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 10
houses = int(input()) dollar = 2/houses*100 from math import ceil print (ceil(dollar))
10th Feb 2020, 7:38 AM
Сорви Голова
Сорви Голова - avatar
+ 9
I fought with this one for almost a week. Totally grasped that the number had to be rounded, but I didn't pay attention that it had to be rounded up. Must pay attention to those details. #rookiemistake
27th Feb 2020, 11:23 AM
Rabinski
Rabinski - avatar
+ 8
This was though. I am a beginner and I dont know the ceil method, but I found another way houses = int(input()) #your code goes a = 2/houses*100 if a %1 > 0 and a %1 < 0.5: b = 1+a print (round(b)) else: print (round(a))
27th Nov 2021, 7:12 AM
Jerome Grobbelaar
+ 5
Your problem is caused because of way the round function works... It will round for the nearst integer, but in the middle (.5) the function returns the nearest even number E.g.: >>round(1.5) 2 Using math.ceil will work in this challenge, but you will be rounding all the numbers to up
26th Mar 2020, 8:20 PM
Rodrigo Medeiros
Rodrigo Medeiros - avatar
+ 4
Jerome Grobbelaar Nice workaround! If you want to use ceil() you just need to import the math pack. The codes above show how it's done (it's not very complicated). Stay safe and happy coding!
27th Nov 2021, 9:57 AM
SpaceBarMönkey
SpaceBarMönkey - avatar
+ 2
Thank you! I always thought round() would round up by default. Had the same test result and it drove me nuts. ^^
23rd Mar 2020, 2:39 AM
SpaceBarMönkey
SpaceBarMönkey - avatar
+ 2
Here another solution without usinga math module: houses = int(input()) result= (2/houses)*100 if result % 1 !=0: print(int(result)+1) else: print(int(result))
4th Apr 2022, 9:07 AM
David Lau
David Lau - avatar
+ 1
I was stuck on this for days too. I thought of using round() but acctually it should be math.ceil()
3rd Apr 2020, 10:27 AM
Sy Chew
Sy Chew - avatar
+ 1
Thanks so much everybody, I was stuck too.
20th Jun 2020, 9:03 AM
Hrumpf
+ 1
Wow thanks a lot
23rd Jun 2020, 9:59 AM
Segun Mikael
Segun Mikael - avatar
+ 1
Same problem, same mistake, same solution ! Thanks
24th Aug 2020, 11:46 AM
C0f3t
C0f3t - avatar
+ 1
You have to import math first to work...or else it returns an error of variable not found. Sorry if it it's too basic but for me it was new!! 😑 (1week In the world of programming) import math houses = int(input()) perc_bills=(2*100)/houses print (math.ceil(perc_bills))
16th Feb 2021, 4:29 PM
David Teixeira
0
Can you show us your attempt?
31st Jan 2020, 10:15 PM
HonFu
HonFu - avatar
0
public class Main { public static void main(String[] args) { System.out.println("Enter no of houses"); Scanner sc = new Scanner(System.in); int houses = sc.nextInt(); float dollor = 2; float pod; pod=(dollor*100/houses); System.out.println(Math.round(pod)); } }
26th Mar 2021, 1:39 PM
THARUN REDDY
THARUN REDDY - avatar
0
THARUN REDDY Wrong language (Python tag in the question) ;) Happy coding!
26th Mar 2021, 1:52 PM
SpaceBarMönkey
SpaceBarMönkey - avatar
0
Actually the correct problem shouldn't have round in it ok Plus the 2*100 comes first before the houses This is how it works import math houses= int(input()) print (math.ceil(2*100/houses)) I used only 3 lines and all cases ticked
14th Jul 2022, 2:41 PM
Hackerslord
Hackerslord - avatar
0
Using only what was taught in the intro to python course houses = int(input()) perc = round((2/houses)*100,2) if perc - int(perc)==0: print(int(perc)) else: print(int(perc+1))
18th Feb 2024, 5:53 PM
Angelo Ricardo Batista
Angelo Ricardo Batista - avatar