+ 1

What is the problem with my code? Can someone help?

Code houses = int(input()) chance = round(2/houses*100) while houses>=3: print(chance) break #your code goes here Question You go trick or treating with a friend and all but three of the houses that you visit are giving out candy. One house that you visit is giving out toothbrushes and two houses are giving out dollar bills. Task Given the input of the total number of houses that you visited, what is the percentage chance that one random item pulled from your bag is a dollar bill? 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

31st Mar 2021, 1:02 AM
Ackøh Bwoy
Ackøh Bwoy - avatar
1 Resposta
+ 1
This is the part you missed: A percentage value rounded up to the nearest whole number. Python's round function doesn't always round up. round(3.2) is 3.0. The following should work with minimal changes to your code: import math houses = int(input()) chance = math.ceil(2/houses*100) while houses>=3: print(chance) break The while-loop that breaks after only 1 pass looks a bit silly and there isn't much need for the choices variable, though. The following is a simplified version: import math houses = int(input()) print(math.ceil(2/houses*100))
6th Apr 2021, 1:50 AM
Josh Greig
Josh Greig - avatar