+ 3

How to solve Halloween candy problem?

I had taken a quiz and i tried to solve it but some thing is of i don't what but here its ; Halloween Candy +10 XP 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 I tried this code but i am stuck so help is needed. houses = int(input()) s= 2 / houses * 100 print (round(s))

23rd Aug 2020, 3:48 PM
Max Lwe
Max Lwe - avatar
8 Answers
+ 11
Max Lwe First of all kindly show your attempt then we can surely help you.asking for readymade code isn't allowed. Happy coding
23rd Aug 2020, 3:56 PM
Piyush
Piyush - avatar
+ 7
First try yourself. If you stuck anywhere then we will help you.
23rd Aug 2020, 3:51 PM
TOLUENE
TOLUENE - avatar
+ 5
Change round to ceil
23rd Aug 2020, 5:16 PM
Julia Shabanova
Julia Shabanova - avatar
+ 3
Yes please show your attempt first . without see your attempts we cannot do your help if you facing any error or mistake our community will try to help you but first try to solve by self .
23rd Aug 2020, 3:55 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 3
Kindly use the search bar! It is an FAQ Solution: import math print(math.ceil(200/int(input())))
23rd Aug 2020, 8:44 PM
Namit Jain
Namit Jain - avatar
+ 2
Your approach is right try may be you can solve see logics Input value houese houses dollarHouses = 2; prob = 0; prob = 100 - ((houses - dollarHouses)* 100 // houses); print(prob)
23rd Aug 2020, 4:05 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
I wrote this code , apparently it works with certain inputs but won't work with others so i guess i am stuck . houses = int(input()) s= 2 / houses * 100 print (round(s))
23rd Aug 2020, 3:56 PM
Max Lwe
Max Lwe - avatar
0
I did it, int totalHouses = Convert.ToInt32(Console.ReadLine()); // Calculate the number of dollar bills received int numDollarBills = 2; int numToothbrushes = 1; int numCandies = totalHouses - numDollarBills - numToothbrushes; // Calculate the percentage chance of getting a dollar bill double dollarChance = (double)numDollarBills / (double)totalHouses * 100; int roundedDollarChance = (int)Math.Ceiling(dollarChance); Console.WriteLine(roundedDollarChance);
22nd Mar 2023, 5:50 PM
stbestichhh
stbestichhh - avatar