+ 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
9 Réponses
+ 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)
+ 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
+ 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?"
+ 3
Nicole Krason take a look at the result of this code:
https://sololearn.com/compiler-playground/cig0zTcT43cK/?ref=app
I hope this helps.
+ 1
We cannot see your code: It is only visible to your account.
Put your code in a script on sololearn playground.
0
The word problem: https://www.sololearn.com/coach/4?ref=app
0
Lisa Okay, I updated it
0
Lisa I haven't learned the last bit of code.
I didn't understand why you would multiple it by 100
0
Yeah, I'm not understanding this problem. Sorry for taking your time up