Hey please someone tell me how to avoid float input in this code fruit = int(input()) apple=fruit/2 print(apple//3) | SoloLearn: Learn to code for FREE!

+1

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

5/5/2021 4:24:23 AM

Vishal Tiwari

15 Answers

New Answer

+6

fruit = int(input()) apple=fruit//2 print(apple//3)

+4

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

+2

Please can you give an example.... If any float is given as input then you want to raise an error or something else?

+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)

+1

Ya I know that it returns only the quotient

+1

Thanks for the help

+1

Vishal Tiwari sorry I was wrong. If either the dividend or the divisor is a float, then __floordiv__ will also return a float.

+1

Because the challenge said that half of the input is apple and other half are grapes

0

Example=input=4 Expected output=0 Real output=0.0

0

I want only 0

0

Thanks it worked

0

And leave the remainder as it is and does not show it

0

No you were right

0

You can't enter float in int(input()) code

0

😁😁