Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Fruit bowl task

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.

Ihis task in this way. Is there a better solution than this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

fruit = int(input())
pie = 0
apple = int(fruit /2)


while apple >= 3:
    apple -= 3
    pie += 1
print(pie)

>Solution :

replace the while statement with a floored division.

pie = floor(apple / 3)
print(pie)

to use floor you need to import the math library
it is similar to round but always rounds down and essentially truncates by 0 dp

if you don’t want to use floor, a cleaner syntax is

pie = apple // 3
print(pie)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading