+ 2

What is up with the “Halloween Candy” question ?

I hv been trying to solve this piece of work for an hour now wtf am I doing wrong ?? Code: houses = int(input()) #your code goes here candy = ((2/houses)*100) if ((candy -int(candy)) >0.50): print(int(int(candy)+1)) else: print(int(candy))

29th Oct 2020, 5:00 AM
Toy
7 Respostas
+ 6
Have your tried using math.ceil() function to round up the result
29th Oct 2020, 5:14 AM
Arsenic
Arsenic - avatar
+ 6
Toy that's because in the question, you have been told to round UP the number instead of rounding OFF the number.{ means 2.1 should be converted to 3 instead of 2 } And your second code didn't work as it was incresing the number even if it was a whole number after division.
29th Oct 2020, 5:27 AM
Arsenic
Arsenic - avatar
+ 2
thanks Arsenic it worked but im still a little confused as to why my original code didnt work ?!
29th Oct 2020, 5:19 AM
Toy
+ 2
Arsenic thanks for the clarification 😀
29th Oct 2020, 5:29 AM
Toy
+ 1
also : I aslo used >= 0.50 before and Test 2 came negative
29th Oct 2020, 5:02 AM
Toy
+ 1
update: I used the following code and still Test#2 failed: houses = int(input()) #your code goes here candy = ((2/houses)*100) print(int(int(candy)+1))
29th Oct 2020, 5:12 AM
Toy
+ 1
In cas it was not obvious from the question im a big nub in python, Now i will try math.ceil() function and update soon thanks for suggestion
29th Oct 2020, 5:16 AM
Toy