How to write this code, please tell me, I need to solve such examples 🙏🏻🙏🏻🙏🏻(python) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

21st Jun 2023, 7:54 PM
Amirhossein
Amirhossein - avatar
3 Answers
+ 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).
21st Jun 2023, 8:13 PM
Lisa
Lisa - avatar
+ 3
Koli Refrain from giving ready-made code. Besides, the OP is asking about Python as you can see from the tag.
22nd Jun 2023, 5:19 AM
Lisa
Lisa - avatar
+ 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
21st Jun 2023, 8:16 PM
Junior
Junior - avatar