+ 1

Hey please someone tell me how to avoid float input in this code fruit = int(input()) apple=fruit/2 print(apple//3)

5th May 2021, 4:24 AM
Vaibhav Tiwari
14 ответов
+ 6
Input () always return string. You can round the value if needed. But why you want to divide fruit and return is apple? I mean imagine you input 4 grapes and then expect 2 apples by dividing the grape?! This sounds like a great conceptual fruit salad
6th May 2021, 7:17 PM
::sк::
::sк:: - avatar
+ 2
Please can you give an example.... If any float is given as input then you want to raise an error or something else?
5th May 2021, 4:27 AM
Md. Faheem Hossain
Md. Faheem Hossain - avatar
+ 1
Vishal Tiwari __floordiv__ (the magic method that works behind the operator // ) returns an integer. You can have a look at this one fruit = int(input()) apple=fruit//6 print(apple)
5th May 2021, 4:48 AM
Md. Faheem Hossain
Md. Faheem Hossain - avatar
+ 1
Ya I know that it returns only the quotient
5th May 2021, 5:00 AM
Vaibhav Tiwari
+ 1
Thanks for the help
5th May 2021, 5:01 AM
Vaibhav Tiwari
+ 1
Vishal Tiwari sorry I was wrong. If either the dividend or the divisor is a float, then __floordiv__ will also return a float.
5th May 2021, 5:06 AM
Md. Faheem Hossain
Md. Faheem Hossain - avatar
+ 1
Because the challenge said that half of the input is apple and other half are grapes
7th May 2021, 6:26 AM
Vaibhav Tiwari
0
Example=input=4 Expected output=0 Real output=0.0
5th May 2021, 4:38 AM
Vaibhav Tiwari
0
I want only 0
5th May 2021, 4:38 AM
Vaibhav Tiwari
0
Thanks it worked
5th May 2021, 4:44 AM
Vaibhav Tiwari
0
And leave the remainder as it is and does not show it
5th May 2021, 5:00 AM
Vaibhav Tiwari
0
No you were right
5th May 2021, 5:23 AM
Vaibhav Tiwari
0
You can't enter float in int(input()) code
5th May 2021, 5:24 AM
Vaibhav Tiwari
0
😁😁
7th May 2021, 6:24 AM
Vaibhav Tiwari