0

help with simple python Code

hello everyone. I am tryign the challenges in the app. I've written this code for the problem that asks me to output a percentage value (integer number) rounded up. The problem says that one house are giving toothbrushes, two houses are giving dollar bills and the rest are giving candy, the value that I need is the chance of pulling out a dollar bill from the bag. I dont know what is wrong and Sololearn hides the 3 last tests which are the ones that are giving me problems. I don't know if I explained myself well, here is the code: houses = int(input()) dollar = 2/houses perc = round(dollar*100) print(perc)

10th Jan 2020, 9:56 PM
Tobias Fuentebuena Guardón
Tobias Fuentebuena Guardón - avatar
3 odpowiedzi
+ 2
The round() function won't work, because it may round the result down. You can use math.ceil() instead, which always rounds the result up. To do that, all you have to do is: import math math.ceil(#some decimal number)
10th Jan 2020, 10:03 PM
Jianmin Chen
Jianmin Chen - avatar
+ 2
The task says to round up, so try the ceil() function instead of round()
10th Jan 2020, 10:03 PM
Tibor Santa
Tibor Santa - avatar
+ 1
thank you both, I wasn't aware of that function
10th Jan 2020, 10:17 PM
Tobias Fuentebuena Guardón
Tobias Fuentebuena Guardón - avatar