+ 4
Fruit bowl
I’m using python to solve a exercise. 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. Here is my code for the Fruit bowl exercise: y=int(input()) y//=2 print(y//3) I got error for output. What’s wrong with my code?
25 ответов
+ 16
y = int(input())
y //= 2
print(y // 3)
1. "int" not "in"
2. (x //= 2) instead of (x =// 2)
#Remember that when incrementing, operation comes first before equal (e.g. x += 1)
3. I look at the challenge details and it should be (x // 3) instead of (x // 2).
Additional: You can just use the "2" right away instead of assigning it to a variable first (which can make the code longer and confusing)
I hope this helps. If it is still not solved, please update me. Thanks and Happy Coding!
+ 6
Haha36 I tried your code and it worked fine.
Somehow, try this
print(int(input()//6)
+ 4
Its very easy.See the answer below.
fruit = int(input())
#your code goes here
if fruit > 0:
print(int((fruit / 2) // 3))
+ 3
Seems working fine to me.
Try this:
x = int(input())
y = x // 2
z = y // 3
print(z)
+ 3
Thank you, Simba and Nicko12. I tried your first answer again, both work now
+ 3
This is the easiest solution to this using C++
#include <iostream>
using namespace std;
int main() {
int fruit,pie;
cin>>fruit;
cin>>pie;
fruit = (fruit/2);
pie=fruit/3;
cout<<pie;
return 0;
}
I hope this helps
+ 2
Oh yeah, I didnt notice that I use "x" instead of "y" itself. Thanks for the correction :)
+ 2
fruit = int(input())
#your code goes here
apple = (fruit//2)
pie = (apple//3)
print(pie)
A very basic answer to give you basic understanding
+ 2
#include <stdio.h>
#include<stdlib.h>
int main() {
int fruit,count =0,i;
scanf("%d", &fruit);
fruit =fruit/2;
if (fruit<6)
{
printf ("0");
exit(0);
}
else if(fruit==6)
{
printf("2");
exit(0);
}
else
{
for(i=3;i<fruit;i=i+3)
count++;
}
printf ("%d",count );
return 0;
}
+ 2
For the guy that did it for Java I just did this cuz I was to lazy to write out the other variables:
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int fruit = input.nextInt();
System.out.println((fruit/2)/3);
}
}
+ 1
Thanks, I change that. But I still got error for ouput. Line 2 invalid syntax.
+ 1
fruit = int(input())
halfapples = fruit//2 # half
leftover = halfapples//3 # left in 3 halfs
print(int(leftover))
#Make things simple
+ 1
int main() {
int fruit;
//take input
cin>>fruit;
//your code goes here
int a=(fruit/2)/3;
cout<<a<<endl;
return 0;
}
0
I still got error for output
0
y=int(input())
y//=2
print(y//3)
This is my new code, but I still got error for line 2
0
Haha36 Maybe you'll write
y = y // 2 instead of 'y //= 2' ?
0
fruit = 26
print(int((fruit / 2) // 3)) переаробовал все что мог,вме что нашел на форумах,все равно дает ошибку.
0
I'll be using ' ' for comments
An alternate version I used that might be easier to understand:
fruit = int(input()) 'Whatever number of fruits you have in the bowl'
#your code goes here
apples = fruit // 2 'Apples equals fruit divided by 2'
pie = apples // 3 'Pie equals apples divided by 3, as it takes 3 apples to make a pie'
print(pie) 'Print the pies you can make with the apples in the bowl'
Also, it wants you to print your final variable when it says it needs output.
0
I basically did this and it's fine
x= fruit/2
print (int(x/3))
0
Using java it will work
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int fruit = input.nextInt();
int x = (fruit/2);
int y = (x / 3);
System.out.println(y);
//your code goes here
}
}