0

What's the problem in my code!?

fruit = int(input()) # your code goes here fruit = 26 print("No. of fruits:") apple = fruit // 2 pie = apple // 3 print("No. of pie is", pie) Why the compilation error occurs for 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

25th Dec 2023, 2:54 AM
Death Beliver
Death Beliver - avatar
4 Respostas
+ 3
fruit = int(input()) #your code goes here apple = fruit // 2 pie = apple // 3 print(pie)
25th Dec 2023, 3:09 AM
Sreeju
Sreeju - avatar
+ 2
The issue lies in the line where you directly assign the value of 26 to the variable fruit, disregarding the input statement, and thereby, it does not prompt for user input. This essentially hardcodes the value as 26. To resolve this, simply remove the line where the value is hardcoded as 26 and use only the input statement to capture the user's input.
25th Dec 2023, 8:25 AM
dancers
dancers - avatar
+ 1
As mentioned by Sreeju , you don't need to give a specific value to fruit variable which needs an input and only print pie variable and remove the string.
25th Dec 2023, 5:14 AM
卂ㄚㄩ丂卄
卂ㄚㄩ丂卄 - avatar
+ 1
The code you're suggesting does not cause a compilation error. However, it does cause a runtime error on the line `fruit = int(input())` because in this context, you can't input data manually. Your code proposes the following algorithm: 1. Get the total number of fruits. 2. Half of them are apples, so divide the total number of fruits by 2 to get the number of apples. 3. Since it takes 3 apples to make a pie, divide the number of apples by 3 to get the number of pies. Your code correctly solves the task. However, to make it work in this context, you would need to pass the value for the `fruit` variable directly, as in the following example: ```python fruit = 26 apple = fruit // 2 pie = apple // 3 print("No. of pie is", pie) ``` In this case, you will get the answer "4", which corresponds to the sample output.
26th Dec 2023, 3:24 AM
Максим Трояшкин