+ 8
I want explanation in this code any one help me please
Explanation https://code.sololearn.com/cPiC4E1MJ2m3/?ref=app
33 Answers
+ 7
fruit = int(input())
def apple(data):
data = data//2 # this code line was data = data/2 before solving
return data
b = apple(fruit)
print (b // 3)
----------------------------------------------
fruit=int(input()) converts a string into integer so basically asking a user to enter an integer
b=apple(fruit)
here apple function is called with fruit as argument for the parameter data and result returned from the apple function is assigned to variable b
b//3 is called floor division
If b is 7 then you will get 2 as output
In function apple ,
In line data=data//2 ,Data is assigned the result as a evaluation of data//2 and returned back to the function call
+ 7
Md. Nasif-ur-Rahman Rimon thank you a lot ,thank you so much now i am clear
+ 3
Md. Nasif-ur-Rahman Rimon yeah and thank you for explaining me how to mention in comments
+ 3
The code is very simple and straightforward first it takes input from the user the change it into integer (because it is string by default) and then pass it into a function named apple which gives the remainder of input when divided from 2 and then it stores the value in b variable the. It prints the remained of b with 3
Read this comment while reading the code at the same time you will easily get what I am saying in
2-3 times 🙂🙂
+ 3
+ 3
This code was just about dividing the total number of fruits by 2 to have the half(number of apples) and now dividing the number of apples by 4 to know how many pies you can do.it is simple arithmetic
+ 2
#First,
fruit=int(input())
#You called function
def apple(data):
#Second
data=data//2
return data
#Recall
b=apple(fruit)
print(b//3)
#fruit=29
data=29//2=14
return data
#returns 14
b=apple(data) #b=14
print(b//3) #4
+ 2
Md. Nasif-ur-Rahman Rimon actually how we are able to know that we have to take 6 there
+ 2
Yeah
+ 2
i did not undersrood and please tell me how to mention u in comments
+ 2
Abhay hello here in this code first they took apple function with argument as data and again they took fruit as argument i did not understand there and how we are able to know that we have to take 2 and 3 in floor division
+ 2
Md.Nasif-ur-Rahaman Rimon here the test cases are not solved it is showing incorrect answers
+ 2
Md. Nasif-ur-Rahman Rimon please tell me
+ 2
Md. Nasif-ur-Rahman Rimon i got it but i have a doubt why we used floor division why cant we use% ?
+ 2
Md. Nasif-ur-Rahman Rimon ok thank you
+ 2
Md. Nasif-ur-Rahman Rimon do u know how to do gotham city task in c 😊
+ 1
Md. Nasif-ur-Rahman Rimon how we are able to know that we have to use only floor division
+ 1
Md. Nasif-ur-Rahman Rimon i am getting error in c
+ 1
Md. Nasif-ur-Rahman Rimon pls shate ur code pls i did npt save it
+ 1
Md. Nasif-ur-Rahman Rimon Sorry bro i am not bro i am sister please tell me how to share it bcoz i dont know and iam a beginner 😅