0
How to write this code, please tell me, I need to solve such examples 🙏🏻🙏🏻🙏🏻(python)
You have a bowl on your counter with an even number of pieces of fruit in it. Half of them are bananas, and the other half are apples. You need 3 apples to make a pie. Task Your task is to evaluate the total number of pies that you can make with the apples that are in your bowl given to total amount of fruit in the bowl. Input Format An integer that represents the total amount of fruit in the bowl. Output Format An integer representing the total number of whole apple pies that you can make. Sample Input 26 Sample Output 4
3 odpowiedzi
+ 5
Try to reproduce the calculation for the given example:
26 fruit pieces, that means 13 apples.
How many pies can you make with 13 apples? (Hint: use floor division).
+ 1
amir Can you share your attemp at trying it? Try breaking it down into simple steps.
- We are given an EVEN number of peices of fruit.
- half are bannanas and HALF are apple. WE ONLY NEED THE APPLES. HALF IS 2 so divide the number of pieces of fruit by 2.
- 3 apples are needed to make a pie and we need to know how many pies we can make. So we can divide the that number that we split and divide it by 3 like they did in the example.
- But something is off, 13/2 = 4.333 which is a decimal number. We can use the round function which I would recommend looking up to round the number down or up depending on the number.
- Now that we have our answer we can then print that out.
Now that we broke it down and i kind of explained it to you, you can simply this even more into small steps in which you can follow and create it.
Edit: Sorry dont round it since round returns a floating point number you can just cast it as an int, and check if number that you divided by 2 is greater than 3