Code Coach: Halloween Candy | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Code Coach: Halloween Candy

I need help to explain how you can turn this word problem into code. I broke down the word problem (as someone suggested to me earlier) but I'm not understanding this word problem (I stuggle with word problems to begin with) Anyway, can anyone give me some pointers as to where I might be going wrong? My attempt at the code: https://sololearn.com/compiler-playground/cGRa8iXQp7yP/?ref=app

5th Mar 2024, 3:28 PM
Nicole Krason
9 Answers
+ 3
You visit x houses (that's the input number). 2 of the x houses give you a dollar, that is 2/x is the proportion of dollars to houses. In order to calculate the percentage from the proportion, multiply the proportion by 100. Now you need to round up the result. To do so, use the ceil function from the math library: import ceil from math res = ceil(myresult)
5th Mar 2024, 3:50 PM
Lisa
Lisa - avatar
+ 3
The task instruction says: "A percentage value rounded up to the nearest whole number." If you visit 4 houses, you get a proportion of 2/4 = 0.5. What is 0.5 in percent? it is 0.5 * 100 = 50
5th Mar 2024, 4:04 PM
Lisa
Lisa - avatar
+ 3
The question boils down to: "You have x items in your bag. 2 of them are dollars. How many percent of the items are dollars?"
5th Mar 2024, 4:08 PM
Lisa
Lisa - avatar
+ 3
Nicole Krason take a look at the result of this code: https://sololearn.com/compiler-playground/cig0zTcT43cK/?ref=app I hope this helps.
5th Mar 2024, 6:17 PM
Solo
Solo - avatar
+ 1
We cannot see your code: It is only visible to your account. Put your code in a script on sololearn playground.
5th Mar 2024, 3:38 PM
Lisa
Lisa - avatar
5th Mar 2024, 3:29 PM
Nicole Krason
0
Lisa Okay, I updated it
5th Mar 2024, 3:42 PM
Nicole Krason
0
Lisa I haven't learned the last bit of code. I didn't understand why you would multiple it by 100
5th Mar 2024, 4:01 PM
Nicole Krason
0
Yeah, I'm not understanding this problem. Sorry for taking your time up
5th Mar 2024, 4:05 PM
Nicole Krason