+ 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))
7 Respostas
+ 6
Have your tried using math.ceil() function to round up the result
+ 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.
+ 2
thanks Arsenic it worked
but im still a little confused
as to why my original code didnt work ?!
+ 2
Arsenic thanks for the clarification 😀
+ 1
also : I aslo used >= 0.50 before and Test 2 came negative
+ 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))
+ 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