#Basic Python doubt
22 messages · Page 1 of 1 (latest)
int() converts to integers
Integers can't have decimal values (aka floating point) -> it breaks
Try using float() instead
It should convert 2.3 into 2 then y=2 now y+40= 42
But it gives an error
Works fine for integral inputs
If we enter x=2.3
As input
So you want to round it down?
You're passing in a floating point number here, your input returns a string though
So this 2 is in form of string value?
When we use int(2.3)
Your x in this code is of type str
x = input() # type(x) = str
y = int(x) # exception, can't convert it properly
x = 2.5 # type(x) = float
y = int(x) # y = 2