+ 1

Trick or Treat challenge

Hey all, The Trick or Treat challenge seems pretty straightforward — I think I’ve solved it, but the three tests that are hidden in the SoloLearn challenges are coming out wrong. I don’t know why, because I can’t see the answers. Anyone know what could be going wrong? The challenge: Two of the houses that you will trick or treat at will give out a dollar bill. What is the percentage chance that you will randomly draw a dollar bill from your candy bag, after you visit (x) number of houses? 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 My answer (which works for 2/5 cases): houses = int(input()) x = 2/(houses)*100 print("%.0f" % x) I also tried to print(round(x)), which provides the same results.

15th Apr 2020, 6:33 AM
2 Answers
+ 2
to round up use math.ceil import math and print math.ceil(x) but to calculate x do this x=2.0/houses*100 else, you'll do an integer division which will round down the result if it's not whole.
15th Apr 2020, 6:47 AM
John Robotane
John Robotane - avatar
John Robotane ah! thanks so much!
15th Apr 2020, 3:56 PM