+ 1

Is this code correct. I have attached the code below along with the question

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 fruit = int(input ()) apples=fruit/2 if (apples%3==0): values=apples/3 print ("this much can be made form this apple",values) else: val=apples//3 values1= apples%3 print("this much can be made",val) print ("the left ones",values1) #your code goes here

27th Sep 2022, 3:05 PM
Nevin Zachariah John
Nevin Zachariah John - avatar
3 Answers
+ 7
Nevin Zachariah John , we could fix your code but we should re-think what we have to do: > take an even number as input (number of all fruits) e.g. 26 > divide this number by 2, since half of the fruits are bananas. use an integer division // since an integer number is expected. result is 13, so we have 13 bananas (26 // 2 = 13) > divide the number of bananas by 3, since we need 3 bananas to make one pie. use an integer division // since an integer number is expected.   result is 4 (13 // 3 = 4)   > output the result of the last division. so we need only these 2 operations. >>> also notice: output only the requested information, no additional textz or what ever...
27th Sep 2022, 7:29 PM
Lothar
Lothar - avatar
+ 1
Expected Output : An integer representing the total number of whole apple pies that you can make. Sample case : 4 Check with your output for a sample input of 26
27th Sep 2022, 3:19 PM
Jayakrishna 🇼🇳
+ 1
Side comment: rethink the need of each variable. "values" and "val" have the same information. Also, always use descriptive names: "values" and "values1" don't show the difference between the variables purposes.
28th Sep 2022, 3:33 AM
Emerson Prado
Emerson Prado - avatar